[Python-Dev] Add a -z interpreter flag to execute a zip file

Phillip J. Eby pje at telecommunity.com
Thu Jul 12 19:58:13 CEST 2007

At 01:46 AM 7/13/2007 +1000, Nick Coghlan wrote:
>The current version of runpy doesn't accept any options, but it 
>would be pretty easy to make the following changes:
>1. Accept a -p option that prepends path entries. These path entries 
>would be combined into a single list from left to right on the 
>command line, then the whole list prepended to sys.path. If at least 
>one -p option is given, the default '' entry would be removed from 
>sys.path (the current directory could be added back in explicitly via -p '.').
>2. Attempt to run the module __main__ if no module is otherwise specified
>Startup would be fractionally slower than it would be with the 
>C-level option, but the code would be much simpler, and the new 
>feature would be readily available on any Python implementation 
>which can execute the runpy module.
>The relevant shebang line to be prepended to a zip file would then 
>look something like:
>#!/usr/bin/env python -m runpy -p

I don't have any particular objection to using runpy for this, but I 
believe that this shebang line won't actually work on certain non-BSD 
OSes, such as most Linux versions, which allow you to have at most 
*one* argument to a #! line, and will combine anything after the 
executable portion into a single argument.  This means that the only 
workable form of this line for cross-platform use is:

#!/usr/bin/python2.6 -z

And of course that won't work if Python is somewhere else.  You can't 
both use env to invoke Python, *and* expect arguments to work.  env 
will receive a single argument of "python -m runpy -p", which it will 
then try to invoke.  On Mac OS and various other BSDs, your example 
will work correctly, but it won't work most anywhere else, as few 
OSes actually support passing individual arguments from a #! line.  See:


More information about the Python-Dev mailing list