Hi, Luyutin,
May I contact you? I also from Taiwan and wandering know how to use Pyinstaller to pack streamlit project.
Masaz
Hi, Luyutin,
May I contact you? I also from Taiwan and wandering know how to use Pyinstaller to pack streamlit project.
Masaz
Hello! Iāve been scrolling through this thread for a few days since itās been very useful throughout my development process. I wanted to share how my setup looks like for reference, deriving from hmasdev solution and jvcs 's guide.
Directory
WORKINGDIR
- program.exe
- .streamlit/ # my program requires secrets.toml
- PROGRAMDIR/
- .venv/ ...
- dist/
- program/
- toc files
- hooks/
- hook-streamlit.py
- resources/
- icon.png
- src/
- main.py
- build.ps1
- run_main.py
- program.spec
build.ps1
.venv/Scripts/Activate.ps1
clear
pyinstaller --onefile -n "program" -i "./resources/icon.png" --hiddenimport ... --additional-hooks-dir=./hooks --workpath ./dist --distpath "../" --add-data "./src:./program/src" run_main.py --clean
& "../program.exe"
--hiddenimport ... tag --add-data tag, meaning I donāt touch the .spec file--distpath "../" tag to output at WORKINGDIR instead of PROGRAMDIR--workpath ./dist to keep all working build files in somewhere organised\src\ and referenced it in --add-datarun_main.py (Dkdatascientist 's solution)
import os
import streamlit.web.bootstrap
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))
flag_options = {
"server.port": 8501,
"global.developmentMode": False,
}
streamlit.web.bootstrap.load_config_options(flag_options=flag_options)
flag_options["_is_running_with_streamlit"] = True
streamlit.web.bootstrap.run(
".\src\main.py",
False,
['run'],
flag_options,
)
_main_run_clExplicit() magic function in streamlit.web.clihooks/hook-streamlit.py (Jason7 's solution)
from PyInstaller.utils.hooks import collect_all
datas, binaries, hiddenimports = collect_all('streamlit', include_py_files=False, include_datas=['**/*.*'])
Things I want to improve:
--hiddenimport.streamlit back to the PROGRAMDIR instead of the WORKINGDIR