简体   繁体   中英

cx_Freeze error when converting .py to .exe

So I have been looking everywhere for ways to convert .py to .exe, such as py2exe and cx_Freeze. I have gotten cx_Freeze close to working, but I have gotten an error and I don't know how to fix it and don't see it posted anywhere online. Does anyone know what this error is and, more importantly, the easiest way I could fix it? I am trying to convert a simple program called catanimation.py as a test, which has a picture involved called cat.png. Everything is in a folder called "attempt" on my desktop. Here is a screenshot of the folder, the files, and the command prompt error: Click here .

I also have the code written here:

    #This is setup.py
    import cx_Freeze

    executables = [cx_Freeze.Executable("catanimation.py")]

    cx_Freeze.setup(
        name="Cat Animation",
        options={"build_exe": {"packages":["pygame"],
                               "include_files":["cat.png"]}},
        executables = executables

        )

Here is the command prompt information:

    C:\Users\Nick\Desktop\attempt>setup.py build
    running build
    running build_exe
    Traceback (most recent call last):
      File "C:\Users\Nick\Desktop\attempt\setup.py", line 10, in <module>
executables = executables
      File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
distutils.core.setup(**attrs)
      File "C:\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
      File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
      File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
      File "C:\Python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
      File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
      File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
      File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 231, in run
metadata = metadata)
      File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 130, in __init__
        for n in self._GetDefaultBinPathExcludes() + binPathExcludes]
      File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 270, in _GetDe
    faultBinPathExcludes
        import cx_Freeze.util
    ImportError: DLL load failed: %1 is not a valid Win32 application.

    C:\Users\Nick\Desktop\attempt>

I am currently using Python 3.4.0 with pygame and cx_Freeze. Please help me figure out the problem and how to fix it so I can make python games into executable files with cx_Freeze! Thanks in advance if you reply!!

Alright, I figured it out. It was confused between 32 and 64 because I had older versions of Python also installed, and upon removing them so only 3.4 was left, and then copying the 3.4 files into the filder with setup.py, the command prompt for Python setup.py build worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM