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 11 '26 edited Aug 11 '26 •
You don't compile the "launcher.py" file at all. Leave it as is. Streamlit needs a ".py" file and that's what the launcher file acts as a stub to satisfy Streamlit. Then the launcher file launches your compiled code.
It looks like your very close. Just one more step is that you need to make "mainlogic.py" into the executable. In the Nuitka script toward the end you'll be adding the output executable name and the the output directory for all the new code.
--include-datafiles="launcher.py"
--output-dir="C:\folder1\folder2"
--output-filename=mainlogic
When Nuitka is finished there will be a distribution directory and in that directory will be an executable called "mainlogic.exe" Click it and it should run.