crossplatform py2exe - would it be useful?

Alex Martelli aleax at aleax.it
Thu Aug 7 16:45:50 EDT 2003


Oren Tirosh wrote:
   ...
>> > 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.

If there's a __main__ in the zip, we could remove (even assuming it's
already there) the yet-empty sys.modules['__main__'].

> 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

So, I reiterate an idea I've already expressed: key on the executable
file's name.  If it's at least six characters long and the first six
characters are (case-insensitive) 'p', 'y', 't', 'h', 'o', 'n' in this
order, forget the whole thing and proceed like now; in other words,
use whatever new tricks we insert *if and only if* the executable file's
name does NOT start with (case-insensitive) 'python'.

> 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
> arguments.

I suspect "obscure environments" may make it hard for py2exe to find
the needed signature and get at the 'configuration area' (depending on
how executable files are stored when seen as stream of bytes).  Still,
such an area would also be useful for other purposes, as you mention
(e.g., supplying the -O switch "at compile time", and the like).  So,
perhaps, we could simply test the executable's name FIRST, and if the
name starts with "python" just do nothing, otherwise look at the
configuration area (string) and so on.  On any "obscure environment"
where the set of tricks doesn't work, one would simply have to avoid
renaming or copying the python interpreter to weird names, and otherwise
would be just about as well or badly off as today.


Alex





More information about the Python-list mailing list