How to build a single python file from multiple scripts?

I found this useful:

http://blog.ablepear.com/2012/10/bundling-python-files-into-stand-alone.html

In short, you can .zip your modules and include a __main__.py file inside, which will enable you to run it like so:

python3 app.zip

Since my app is small I made a link from my main script to __main__.py.

Addendum:

You can also make the zip self-executable on UNIX-like systems by adding a single line at the top of the file. This may be important for scripts using Python3.

echo '#!/usr/bin/env python3' | cat - app.zip > app
chmod a+x app

Which can now be executed without specifying python

./app

Leave a Comment