How to build a single python file from multiple scripts?

Solution 1:

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

Solution 2:

Use stickytape module

stickytape scripts/blah --add-python-path . > /tmp/blah-standalone

This will result with a functioning script, but not necessarily human-readable.

Solution 3:

You can try converting the script into an executable file. First, use:

pip install pyinstaller

After installation type ( Be sure you are in your file of interest directory):

pyinstaller --onefile --windowed filename.py

This will create an executable version of your script containing all the necessary modules. You can then transfer (copy and paste) this executable to the PC or machine you want to run your script.

I hope this helps.