using: pyinstaller v. 6.6.0
pyi-makespec --icon=icon.ico --add-data main.py:. --add-data cert:. --add-data cert:cert --add-data static:static  --add-data .streamlit:.streamlit --hidden-import streamlit --collect-all streamlit --copy-metadata streamlit run_main.py 
pyenv virtualenv <version> <env-name>
#or
python -m venv .<env-name>pyenv activate <env-name>
#or
.\op a #.venv\Scripts\activate.batpython --versionpyenv deactivate
#or
.\op d #.venv\Scripts\deactivate.bat#I'm using streamlit==1.8.1 But in the 
#Tutorial I explain what could change for us.
#So You could use the latest
pip install streamlit pyinstallerecho > app.pyecho > run_app.pyimport streamlit as st
if __name__ == '__main__':
    st.header("Hello world")from streamlit.web import cli 
#this uri depends based on version of your streamlit
if __name__ == '__main__':
    cli._main_run_clExplicit('app.py', 'streamlit run')
    #we will CREATE this function inside our streamlit framework#... def main(log_level="info"):
# [...]
# you can you the name you prefer ofcourse
# as long as you use underscore at the beginning
def _main_run_clExplicit(file, command_line, args=[],flag_options={}):
    main._is_running_with_streamlit = True
    bootstrap.run(file, command_line, args,flag_options)
# ...if __name__ == "__main__":
#...    main()from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('streamlit')(if you are using the auto-py-to-exe we can't edit spec files from here we should edit from the interface in the advance options)
pyinstaller --onefile --additional-hooks-dir=./hooks run_app.py --clean
#the onfile indicate we are create a output file join
# everthing in it's binary
#Some use case you actually need --ondir instead
#the --clean delete cache and remove temporary files before building.
#--additional-hooks-dir An additional path to search for hooks. This option can be used multiple times.[global]
developmentMode = false
[server]
port = 8502xcopy /s /e .streamlit output/.streamlit
#select D = directorycopy app.py output/app.py...
a = Analysis(
    //...
    datas=[
        (".env/Lib/site-packages/altair/vegalite/v4/schema/vega-lite-schema.json",
        "./altair/vegalite/v4/schema/"),
        (".env/Lib/site-packages/streamlit/static",
        "./streamlit/static"),
        (".env/Lib/site-packages/streamlit/runtime",
        "./streamlit/runtime"),
    //...)
...# 
# this path pair should be in that way
# but I believe it is because we add the tuple as this templete
# (absolut_path, parent_path)
# so for files that is in the root of `Lib/site-packages` 
# We can add only the dot as parent 
# i.e: (".envir/Lib/site-packages/wmi.py",".")
# for folders the behaviour is the samepyinstaller run_app.spec --cleanHuge Thanks To: hmasdevI'm organizing the solution from hmasdev in the Streamlit Forum