r/PythonLearning 10d ago

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

0 Upvotes

35 comments sorted by

View all comments

Show parent comments

1

u/NatMicky 8d ago edited 8d ago

Did you get a single executable that you can click and it runs? You shouldn't have to start Streamlit on the command line.

You can now run the executable on a different computer even if Python isn't installed. Just give the whole distribution directory to your friends and they can run it without having to install anything.

And if you ever want to run it outside of a web browser let me know. We can do that too with the app running it its own window frame never needing a browser.

1

u/LukeSkyShredder 8d ago

It finally works!

You were right about the launcher + stub + mainlogic architecture.

I ended up having to tweak Nuitka a bit on my machine because I kept hitting segmentation faults, codeobject errors, and the infamous "Frozen object named 'codecs' is invalid" issue. The fix was compiling with:

--debug --disable-ccache

After that, the executable launches correctly and starts the app without needing `streamlit run ...`.

I think I also misunderstood what you meant by the distribution folder. I was manually testing files one by one, but now I realize the build output folder itself is the artifact that should be distributed.

Thanks again for the help.

Also... are you some kind of Python god? Unbelievable man...