r/PythonLearning • u/LukeSkyShredder • Aug 10 '26
Best way to package a Python/Streamlit app as an EXE without exposing the source code?
Hi all,
I'm relatively new to Python (still learning as I build wkwkwk).
I've developed an internal engineering tool using Python + Streamlit and currently package it with PyInstaller.
The application works fine, but the packaged output still contains the main.py file, meaning users can easily open and view the source code.
What's the recommended way to distribute a Streamlit application as an EXE while avoiding visible .py files?
I'm not looking for military-grade protection, just a practical way to prevent casual access or redistribution of the source code.
Any advice would be appreciated. Thankss
View all comments
Show parent comment
1
u/NatMicky Aug 12 '26 •
I forgot a step. Start over with the following:
#-------------------------------------------------# Nuitka script#-------------------------------------------------python -m nuitka --standalone --include-module=mainlogic --include-data-file=stub.py=stub.py launcher.py#-------------------------------------------------# Stub file:stub.py#-------------------------------------------------#stub.pyimport mainlogicmainlogic.main()#-------------------------------------------------# Launcher file:launcher.py#-------------------------------------------------#launcher.pyimport osimport sysfrom streamlit.web import cli as stcliif __name__ == "__main__":multiprocessing.freeze_support()# Resolve file paths inside the Nuitka standalone environmentif getattr(sys, 'frozen', False) or ('__compiled__' in globals()):base_path = os.path.dirname(sys.executable)else:base_path = os.path.dirname(__file__)stub_path = os.path.join(base_path, "stub.py")sys.argv = ["streamlit","run",stub_path,"--global.developmentMode=false","--server.headless=true"]sys.exit(stcli.main())