With “zipapp“, you can create a executable Python archive with all its dependencies.
Basic Usage
Here is an example. Use the following Python file as the target script.
1 | from termcolor import cprint |
Run the following commands to create the “pyz” package file with “inside.py”.
1 | mkdir build |
After the “test.pyz” file is generated, you can run “python dist/test.pyz” to execute the Python package.
Advanced Usage
In some case, your code inside a “pyz” file needs to call external Python code out of the “pyz” file. Here is an example.
1 | from termcolor import cprint |
1 | from termcolor import cprint |
Run the following commands to create the “pyz” package file with “inside.py” only.
1 | mkdir build |
Run the following command to execute the “test.pyz” file.
1 | # "/Users/auser/test/dist" is where the "outside.py" resides. |