将.py转换为.exe时出现cx_Freeze错误

时间:2016-04-25 01:36:42

标签: python pygame cx-freeze

所以我一直在寻找将.py转换为.exe的方法,例如py2exe和cx_Freeze。我已经让cx_Freeze接近工作,但我遇到了一个错误,我不知道如何修复它,并且看不到它在网上任何地方发布。有谁知道这个错误是什么,更重要的是,我能解决它的最简单方法? 我试图将一个名为catanimation.py的简单程序转换为测试,其中包含一个名为cat.png的图片。一切都在我桌面上名为“尝试”的文件夹中。以下是文件夹,文件和命令提示错误的屏幕截图:Click 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

        )

以下是命令提示信息:

    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>

我目前正在使用带有pygame和cx_Freeze的Python 3.4.0。请帮我弄清楚问题以及如何修复它,以便我可以使用cx_Freeze将python游戏变成可执行文件!如果你回复,请提前致谢!!

1 个答案:

答案 0 :(得分:1)

好吧,我明白了。它在32和64之间混淆了,因为我也安装了旧版本的Python,并且在删除它们时只留下3.4,然后使用setup.py将3.4文件复制到filder中,Python setup.py构建的命令提示符成功了!