Calling py2exe from another module?

Thomas Heller theller at python.net
Wed Mar 12 10:51:10 EST 2003


Alexander Skwar <lists.ASkwar at email-server.info> writes:

> Hello!
> 
> I'd like to create Windows executables for my application with
> py2exe.  This works very fine, when I call "setup.py py2exe" from a
> command line.
> 
> Now I'd like to call py2exe from a wrapper module, because besides
> creating the EXE, I'd like to some other things as well.
> 
> Well, that's where I'm stuck.
> 
> I tried to import the setup module but I don't know what to do
> next.  I also tried to instantiate a object of the class 
> py2exe.build_exe.py2exe which I passed this parameter:
> 
> setup(
>         name='XboxIfy', 
>         scripts=['XboxIfy.py'], 
>         description='Rename files in such a way, that they can be transferred to Xbox', 
>         data_files=[('.',((glob.glob('*.gif') + glob.glob('*.ico')) + glob.glob('*.txt')))]
>     )
> 
> But when I call my script which should call py2exe, I get the 
> following "error":
> 
> usage: MakeEXE.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
>    or: MakeEXE.py --help [cmd1 cmd2 ...]
>    or: MakeEXE.py --help-commands
>    or: MakeEXE.py cmd --help
> 
> error: no commands supplied
> 
> I suppose, I forgot to do something.
> 
> So, how do I call py2exe from within another module?

It isn't supposed to be used this way. The setup script that you write
is a *script*, not a *module*.  The distutils' setup() function it calls
is the main() function, so to speak: It parses the command line args,
for example, and complains if they are not acceptable.

The proper way to extend the work this function does is to write
custom distutils commands (there are examples on the web which you
could use as a starting point), but this is an advanced issue because
it's not documented.

Do yourself a favor and do it the way Peter suggests.

Thomas




More information about the Python-list mailing list