[Python-Dev] hook for standalone executable

Oren Tirosh oren-py-d at hishome.net
Sun Aug 10 16:51:58 EDT 2003

On Sat, Aug 09, 2003 at 06:06:26PM +0200, "Martin v. Löwis" wrote:
> Skip Montanaro wrote:
> >It wasn't me. I agree it seems a tad fragile, however it will probably be 
> >a
> >lot easier than coming up with a "portable" way for the interpreter to know
> >its size.  I'd suggest a command line flag but I don't think that's going 
> >to
> >fly either.
> I recommend to drop the requirement that simple appending of .zip file 
> needs to work, and suggest to use platform-specific mechanisms on each 
> platform. These mechanisms should arrange to patch a variable, 
> Py_EmbeddedZipfile. 

If the solution is patching a variable in the executable there is one
variable that controls all aspects Python initialization: argv.

A variable called Py_OverrideArgv will contain by default a unique 
signature. An external tool can search for this signature and replace it
with a customized string. If not modified, the interpreter will use the 
real argv. If it is modified the interpreter will use it instead of argv
and apply all standard argv processing including flags and -c. The only 
difference will be that PySys_SetArgv will still be called with the real 
argv to make the real arguments accessible to the script. I think the 
modification should be less than 20 lines of code.

A tool like py2exe could take the python interpreter, copy it and append
the zip archive. While copying it can search for the unique signature 
and replace it with something like:

'-O -Whatever -c "import sys; sys.path.append(sys.executable); import boot'


More information about the Python-Dev mailing list