Python zipapp Module
Example
Create a simple executable zipapp:
import zipapp
import os
# Create a simple script directory
os.makedirs('myapp', exist_ok=True)
with open('myapp/__main__.py', 'w') as f:
f.write("print('Hello from zipapp!')")
# Create executable zipapp
zipapp.create_archive('myapp', 'myapp.pyz')
print('Created myapp.pyz')
Try it Yourself »
Definition and Usage
The zipapp module allows you to create executable Python zip archives (zipapps) that can be run directly by the Python interpreter.
A zipapp is a ZIP file containing Python code with a __main__.py entry point, optionally with a shebang line to make it executable on Unix-like systems.
Note: Zipapps are useful for distributing Python applications as single-file executables without requiring installation.
Members
Member | Description |
---|---|
create_archive() | Create an executable archive from a source directory or file. |
get_interpreter() | Get the interpreter path from an existing zipapp archive. |
ZipAppError | Exception raised for zipapp-related errors. |