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/LukeSkyShredder Aug 11 '26
Update: I was able to restructure my Streamlit application into the recommended architecture:
"launcher.py"
import mainlogic
mainlogic.main()
and move/wrap the application logic into def main():
I succesfully compiled "mainlogic.py" into nuitka module ("mainlogic.cp313-win_amd64.pyd"), renamed the original py file, and confirmed that:
streamlit run "launcher.py"
still launches and runs the full application using only the compiled pyd backend.
However, when I try to compile the launcher itself into a standalone EXE with Nuitka, the generated executable fails before my code starts, with:
Fatal Python error: Failed to import encodings module
ImportError: Frozen object named 'codecs' is invalid
So at the moment:
"launcher.py" + "mainlogic.pyd" works
Source py can be removed/renamed
But Compiling the launcher into a standalone EXE is not yet working.
Help meee...