Distributing python applications as a zip file

Chris Angelico rosuav at gmail.com
Wed Jul 23 03:59:52 EDT 2014


On Wed, Jul 23, 2014 at 2:23 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Linux, you can even hack the zip file to include a shebang line!
>
>
> steve at runes:~$ cat appl
> #!/usr/bin/env python
> # This is a Python application stored in a ZIP archive.
> steve at runes:~$ cat appl.zip >> appl
> steve at runes:~$ chmod u+x appl
> steve at runes:~$ ./appl
> NOBODY expects the Spanish Inquisition!!!

This, by the way, depends on a feature of the zip file format: you
start reading from the back, with the key indexes, and then come to
the front. It's designed to allow various self-extracting archive
formats to be easily unzipped (imagine, if you will, a SFX built for
Windows when you're on Unix - rather than try to run the program (with
all the difficulties and risks that would entail), you just unzip it),
and it works nicely here too. I suppose, then, it would be possible to
make a minimal Unix SFX prefix: "#!/usr/bin/env unzip\n" on the
beginning of a zip should do the job :)

(Yes, I'm aware that that violates most of the point of an SFX, in
that the target system doesn't need to have pkunzip installed, but
it's still neat how short it can be.)

ChrisA



More information about the Python-list mailing list