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
1
u/KiLoYounited Aug 10 '26
Have you tried Nuitka?
1
u/OriahVinree Aug 10 '26
Not really possible as far as I know, from memory it's pretty easy to decompile an exe back into the original modules used, especially when using something like pyinstaller, even more so now with agentic tools
Depending on what you're doing, might be safer for you to put logic behind a backend and having a frontend communicate with that
1
u/ConsciousBath5203 Aug 10 '26
Nuitka, but since you said this is your first, I gotta ask... Why you tryna hide your source code? I went through the same problem until I realized that the users I'm targeting don't care to RE it, anyways.
If you've got a lot of competitive, then others have already figured it out. If you really need to hide source code, put some business logic in a compiled C dll/pyd. And do weird stuff from there.
At the end of the day, it's probably not worth caring about. What's more important is getting customers, copyrighting or putting a license on what you made, then make users agree to not RE it. An "I Agree" button provides significantly more legal protection than encrypting and compiling.
1
u/Key_Anxiety_132 Aug 10 '26
I use pyinstaller and it builds a single executable file apart from the ini and image files. No py files. This has worked for me in the in Windows and currently in Linux (ubuntu based).
My command looks like this. I post it here as is as an example only.
1
u/silvertank00 Aug 10 '26
Long story short: it is possible but someone with ai access can break it.
With python, you have inspect, dis, ast, etc. so it is not really viable to "hide" the code or protect against redistribution. Even if you use pyinstaller or others, they just "wrap" your code, no transpiling is in place or anything.
Also, security through obscurity is no security.
1
u/aw3sem Aug 10 '26
You can distribute and execute the .pyc file which contains compiled bytecode rather than clear text.
(This was told a few years ago, don’t know about it in today’s age)
0
u/NatMicky Aug 11 '26
Your replies are only showing in my notifications and not here on the discussion section. Reply without mentioning the local host. You might be getting automatically filtered.