tags:

views:

272

answers:

5

When trying to use py2exe to convert a simple Python game I made into exe format, it gave me the following error:

Traceback (most recent call last):
  File "C:\Users\Tali\Desktop\2exe.py", line 4, in <module>
    setup(console=['test.py'])
  File "C:\Python\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 305, in _run
    dlls = self.find_dlls(extensions)
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 389, in find_dlls

    self.dll_excludes)
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 1021, in find_dep
endend_dlls
    import py2exe_util
ImportError: DLL load failed: %1 is not a valid Win32 application.

I searched the web for about an hour, tried changing things in my program. Nothing works. Although my program uses the "random" library, I haven't seen a case in which it caused this kind of problem.

The install script:

from distutils.core import setup
import py2exe

setup(console=['test.py'])

Yes, both the scripts are in the same folder (Desktop). If it matters, I'm running on Windows Vista with Python 2.7

Thank you all very much in advance.

A: 

From your comments, I see that you are doing this in the command prompt:

setup.py py2exe 

from the py2exe tutorial's third step, you should be doing this instead (int eh command promt):

python setup.py py2exe

A second look at the comments on the original question shows that this suggestion has already been made. +1 to joaquin to for this.

To try to answer your question again: Joaquin also mentioned that this might be a path issue. Rather than trying to fix that, you might want to consider the easier option of copying your python files into C:\Python. Then in the command prompt:

cd C:\Python
python setup.py py2exe

This has always worked for me

Hope this helps

inspectorG4dget
This was already indicated in the comments. The op is not able of getting just 'python' producing the python shell.
joaquin
A: 

You can deal with py2exe and the headaches, I tried doing this, even when I had it right, it would error, though I did find the excellent python program gui2exe, this makes it extremely easy to make an exe (or any of the other supported formats).

Gui2exe: http://code.google.com/p/gui2exe/downloads/detail?name=GUI2Exe_0.5.0.zip

Examples: http://code.google.com/p/gui2exe/wiki/GUI2ExeExamples

Zimm3r
And does it also work for non-GUI scripts?
Niv
@niv ya it does, its just a nice gui that seems to solve some problems magically and also makes it easier (ok maybe not magic but my dll problems went away after using it)
Zimm3r
A: 

same problem persits with GUI2Exe... :)

and i am using windows 64-bit os,i think thts not a problem; i installed win32 package for python then also the same problemm persists with py2exe as well as gui2exe!!
A: 

Try installing the Microsoft Visual C++ 2008 Redistributable Package (x86): http://www.microsoft.com/downloads/en/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&amp;displaylang=en

Victor Ionescu
A: 

I had exact the same problem.

Since I have windows 7 64bit, I downloaded py2exe-0.6.9.win64-py2.6.amd64.exe, which I suppose to be the 64bit version of py2exe. but it did not work, and I had the same error.

I changed to py2exe-0.6.9.win32-py2.6.exe, and it worked fine.

I guess you have to match the 32bit or 64bit with the python installation instead of the windows itself.

by the way, "setup.py py2exe" or "python setup.py py2exe" really does not matter, if you instructed windows to open *.py with python during the python installation.

xiao-yu