You could use the zipapp module from the standard library to create executable Python zip archives. It is available from Python 3.5 onwards.
One way to create a bundle is to add a top-level file named __main__.py
, which will be the script that Python runs when the zip executable archive is executed.
Suppose your directory structure is now like this:
└── myapp
├── __main__.py
├── myprog1.py
└── myprog2.py
If your code has external dependencies (e.g. listed in a file named requirements.txt
), install them into the directory using:
pip3 install -r requirements.txt --target myapp/
note 1: This will fill the myapp/
directory with the external dependencies.
note 2: Debian/Ubuntu users may need to use the --system
option for pip3
, because the Debian/Ubuntu version of pip seems to use --user
by default.
Then, create the zip executable archive using:
python3 -m zipapp myapp/
This will create a zip executable archive named myapp.pyz
, which you can execute by running:
python3 myapp.pyz
When the zip executable archive is executed, it is __main__.py
that is run.
If, in addition to Python scripts, you need to include other data files (e.g. text files, PNG images, etc.) used by the Python scripts, see: python: can executable zip files include data files?