crossplatform py2exe - would it be useful?

Oren Tirosh oren-py-l at
Thu Aug 7 21:23:13 CEST 2003

On Thu, Aug 07, 2003 at 02:46:24PM +0200, Thomas Heller wrote:
> Alex Martelli <aleax at> writes:
> > Oren Tirosh wrote:
> >
> >> On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote:
> >>> I'm currently working on a new version of py2exe, which will require
> >>> Python 2.3 and later, because it uses the zipimport mechanism.
> >> 
> >> Now that zipimport is part of Python the code required for bootstrapping
> >> a py2exe runtime is just:
> >> 
> >> myscript -c "import sys; sys.path.insert(0, sys.executable); import foo"
> >> 
> >> This reduces the difference between the custom interpreter supplied with
> >> py2exe and the standard interpreter to just a few lines of C.
> >> 
> >> The obvious question is - why not go all the way and put this little
> >> hook into the standard Python distribution? This way py2exe could be a
> >> platform-independent pure Python application. In fact, py2exe wouldn't
> >> actually be necessary because anyone could create a zip file manually and
> >> append it to the executable but it's more convenient to have a tool that
> >> automates the process and finds the required dependencies.
> >
> > Sounds like a good idea to me, if a sensible name is chosen for the
> > "main module" (I propose 'main':-).
> My choice would have been __main__ :-) Is it really the correct way to
> 'import __main__' instead of 'running' it?

You can't import __main__ - you'll get the one already in sys.modules. 
The code for the main script needs to be executed in __main__'s dict. 

Guido might not like it if the interpreter always attempted to open 
its executable image file to check for an appended zip. It could cause 
problems on some obscure environments. A possible alternative would be 
to have a configuration area inside the executable that can be modified 
by an external program (e.g. py2exe). The program would search for a 
signature string and modify the section after it. The configuration 
area can be as simple as a string that overrides the command line 


More information about the Python-list mailing list