Issue compiling using py2exe on Windows 7 x64

Question:

I am using py2exe to compile my script into an exe file to run on Windows, but I am hitting errors based on my OS, which is Window 7 x64. I am running the below script in cmd using execmaker.py py2exe:

from distutils.core import setup
import py2exe

includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
            'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
            'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
                'tk84.dll']

setup(
    options = {"py2exe": {"compressed": 2, 
                          "optimize": 2,
                          "includes": includes,
                          "excludes": excludes,
                          "packages": packages,
                          "dll_excludes": dll_excludes,
                          "bundle_files": 1,
                          "dist_dir": "dist",
                          "xref": False,
                          "skip_archive": False,
                          "ascii": False,
                          "custom_boot_script": '',
                         }
              },
    windows=['My_Script.py'] #this is the name of the script I'm compiling to exe
)

The actual script I’m compiling into exe isn’t important, because it worked completely fine when I compiled it using bundle_files: 3, which doesn’t bundle any of the files and leaves ~200 .pyo files in a folder.

So let’s get to the center of the problem: As I’m on Win 7 x64, I have the 64-bit version of Python 2.7.5 installed. When I cd down to the file where the execmaker.py and the My_Script.py files are and run it in cmd (execmaker.py py2exe), I get an error message that reads as follows:
error: bundle-files 1 is not yet supported on win64, which I take to mean that it won’t bundle the files because my OS is 64-bit. I thought that maybe this was a problem created because I have 64-bit python installed, but when I uninstalled it, I received the error DLL load failed: %1 is not a valid Win32 application.

The DLL Load error is caused by running 32-bit python on 64-bit Windows. So basically, it doesn’t work with 32-bit or 64-bit python because I’m running 64-bit Windows. Is there a workaround for this, or do I need to install python and all the modules I have been using on a 32 bit machine to do the compiling?

Edit: I did some more research and came up with nothing. For now, unless this question is answered with something more efficient, I guess installing a 32-bit operating system on a partition or through Parallels (which is how I did it) will have to suffice.

Asked By: Ian Zane

||

Answers:

I guess it is too late for you now but for the next soul stuck in this boat, in my opinion, a more efficient way would be to install virtualbox (vb) for free from oracle and then install your 32 bit os on it. That way you don’t have to partition your hard drive or what not, and you can without any risk uninstall the vb just like any other program.

Another option would be to try to work with pyinstaller. I have only used it to make executables for linux systems but I think you can use it on windows too.

Answered By: Sason Torosean

Your problem is that py2exe is 32 bit version and does not work under x64 windows.
If this is the case you, obviously, need 64 bit py2exe and here it is on sf.net.

Answered By: Beglarm

I had a similar problem as the OP. A python app bundled with Py2exe in a 64-bit Windows 7 Python2.7 environment, worked well for a while under 32-bit W7. Early august 2013 it still worked. Late november 2013 it was discovered that it had stopped working because of a version conflict. My best guess is that a Windows update between those dates caused the tighter version check.

I re-bundled the app with Py2Exe on my old 32-bit Vista Python27 dev machine, and it worked again, both under 64-bit and 32-bit Windows.

This answer (from here) was most helpful to me:

The easiest thing to do though is just to make
sure that your 64-bit Windows installation is using a 32-bit Python
installation. py2exe doesn’t really build anything; it just bundles
your source files up with the Python interpreter, so as long as that
interpreter is 32-bit the generated exes should be able to run on
either platform.

For the sake of completeness, this was the error message:

“This version of [module name] is not compatible with the version of Windows you’re running. Check your computer’s system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.”

Answered By: RolfBly

I am also running the application on windows 7. If you are able to, uninstall python 2.7 x64, reinstall python 2.7 x86, and finally install py2exe. This resolved the issue for me.

Answered By: Preston Martin

There is an online exe generator tool (py2exe.net) that “almost” worked for me. I’m programming in Python 2.7 and I got that annoying windows 64 issue when trying to get a standalone executable.

Even if the website mentioned the fact that it is built for Python 3.x programs, I uploaded my program just to try.

My program use pygame calls to png images, so I imported the images on the website as well

I got an executable file that was almost standalone: the image import apparently didn’t work as the executable could only work in a folder containing the images. But still, it’s much better than nothing.

Answered By: Glxblt76
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.