Python, Be Bold!

Marko Rauhamaa marko at pacujo.net
Sat Jan 4 16:19:51 EST 2020


Greg Ewing <greg.ewing at canterbury.ac.nz>:
> You can pass a zip file with a .pyz extension to the python
> interpreter and it will look for a __main__.py file and run
> it.

This discussion has been interesting, and I've now learned about zipapp.
This is really nice and will likely be a favorite distribution format
for Python applications.

My initial instinct would be to use zipapp as follows:

 * The starting point is a directory containing the Python source files,
   possibly with subdirectories. (A simple, two-file example:
   "myapp.py", "auxmod.py".)

   Be sure that "myapp.py" contains the boilerplate footer:

   if __name__ == '__main__':
       main()

 * Test that the program works:

   $ ./myapp.py
   hello

 * Generate the zipapp:

   $ python3 -m zipapp . -o ../myapp.pyz --main myapp:main \
       -p "/usr/bin/env python3"

 * Try it out:

   $ ../myapp.pyz
   hello


Marko


More information about the Python-list mailing list