makeExe.py

Peter Hansen peter at engcorp.com
Mon Jan 26 20:47:19 CET 2004


Premshree Pillai wrote:
> 
> Wrote a simple Python script that makes life a wee bit
> easier when using py2exe:
> 
> """
> makeExe.py
> - Simple Python script to automate the creation
>   of Python executables using py2exe.
> 
[snip]
> fp = open("setup.py","w")
> temp = """from distutils.core import setup
> import py2exe
> setup(name = "%s",
>      scripts = ["%s"],
> )""" % (package,fileName)
> fp.write(temp)
> fp.close()

You could save yourself a fair bit of trouble, and avoid writing a
"setup.py" file to the filesystem (possibly overwriting an existing
one which might be important) by just calling the setup() method 
directly yourself.  The only trick is that it checks sys.argv[] for
the "py2exe" argument, so you have to fake that first:

sys.argv[1:] = ['py2exe']

from distutils.core import setup
setup(name=package,
    scripts=[fileName])

That should do the trick....  if you're interested in integrating the
changes, and maintaining it, I'll forward our own script which you can
pull apart and reuse as required...

-Peter



More information about the Python-list mailing list