This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author andy-chu
Date 2007-06-19.03:40:37
SpamBayes Score
Marked as misclassified
The motivation for this is that distributing a zip file is a very light and easy way to distribute a python program with multiple packages/modules.  I have done this on Linux, Mac and Windows and it works very nicely -- except that you need a few extra files to bootstrap it: set PYTHONPATH to the zip file and run the main function.

With this small patch, you get rid of the need for extra files.  At the bottom is a demo on Linux.

On Windows, you can do a similar thing by making a file that is both a zip file and a batch file.  The batch file will pass %~f0 (itself) to the -z flag of the Python interpreter.

I ran this by Guido and he seemed to think it was a fine idea.  At Google, we have numerous platform-specific hacks in a program called "autopar" to solve this problem.

I have included the basic patch, but if you guys agree with this, I will add some tests and documentation.  And I think it might be useful to include something in the Tools/ directory to do what does below (add a __zipmain__ module and a shebang/batch file header to a zip file, to make it executable)?

I think this may also help to fix a bug with eggs:

IMPORTANT NOTE: Eggs with an "eggsecutable" header cannot be renamed, or invoked via symlinks. They must be invoked using their original filename, in order to ensure that, once running, pkg_resources will know what project and version is in use. The header script will check this and exit with an error if the .egg file has been renamed or is invoked via a symlink that changes its base name.

andychu testdata$ ls  foo.pyc  header.txt

# The main program you're going to run in "development mode"

andychu testdata$ ./ foo bar
argv: ['./', 'foo', 'bar']

# Same program, packaged into a zip file

andychu testdata$ ./ foo bar
argv: ['-c', 'foo', 'bar']

# Contents of the zip file

andychu testdata$ unzip -l
warning []:  51 extra bytes at beginning or within zipfile
  (attempting to process anyway)
  Length     Date   Time    Name
 --------    ----   ----    ----
      243  06-18-07 20:01
      301  06-18-07 19:58
 --------                   -------
      544                   2 files

# Demo script to build an executable zip file.

andychu testdata$ cat header.txt
#!/usr/local/google/clients/python/trunk/python -z

andychu testdata$ cat

# Make a regular zip file.

# Add a shebang line to it.
cat header.txt >

# Make it executable.
chmod 750
Date User Action Args
2007-08-23 15:58:47adminlinkissue1739468 messages
2007-08-23 15:58:47admincreate