Consolidating a Python Application into a Single Page File

I have a strange situation where I need to upload the Python source file to a test server for evaluation, but I want my application to be organized into several files / modules / packages. Unfortunately, the test server is out of control, so I can’t change it so that I can upload a ZIP file containing my code.

Is there an easy way to take a large number of Python source files spanning an application and automatically reduce them to a single source file (or .pyc file)? For simplicity, only one file will be considered an "entry point" and have if __name__ == '__main__'. The final file still needs to be executed by the Python interpreter, so I cannot use the Python-EXE generator.

+5
source share
1 answer

If you cannot download the zip file, perhaps you can follow some of the suggestions contained here . The idea is to create and load a script file that contains a Python shebang line (ignored by the interpreter) added to the zip file archive. You can then either directly interpret the Python interpreter or execute it from the shell. To make this work, you need to use at least Python 2.6.

zip testapp.zip *
echo '#!/usr/bin/env python' | cat - testapp.zip > testapp.py
chmod 755 testapp.py

For execution:

python testapp.py

or

./testapp.py

, , Python , , __main__.py __init__.py, __main__.py . kludge, , , , , . , Python zip-, .

POSIX, script, script.

+4

All Articles