在cx_Freeze中编译后打开图片

时间:2015-01-12 01:03:35

标签: python compilation pygame png cx-freeze

我试图使用cx_Freeze转换pygame游戏,当我尝试运行它时,程序无法打开背景图片。以下是错误消息:

Traceback <most recent call last>:
    File "C:\Python34\lib\site-packages\cx_Freeze\initscrips\Console.py", line 27, in <module>
        exec<code, m.__dict__>
    File "StartGame.py", line 46, in <module>
pygame.error: Couldn't open background1.png

这是我的setup.py

import cx_Freeze

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

cx_Freeze.setup(
    name="The Tragic Tale of Romeo and Juliet",
    options={"build.exe": {"packages":["pygame"], "include_files":["Background1.png"]}},

    executables = executables

    )

1 个答案:

答案 0 :(得分:1)

您应该将所有包与主exe放在同一个文件夹中。文件。如果它们不在同一目录中,则程序无法找到它们。

此外,setup.py必须是这样的;

from cx_Freeze import setup,Executable
setup(name="My game",
         version="1.0",
         options={"build_exe":{"packages":["pygame"],"include_files":["mypicture.png","mysecondpicture.png"]}},
         description="My game!",
         executables=[Executable("filename.py")])

include_files用于包装,如图片,声音等。