【问题标题】:opening pictures after compiling in cx_Freeze在 cx_Freeze 编译后打开图片
【发布时间】:2015-01-12 01:03:34
【问题描述】:

我尝试使用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

    )

【问题讨论】:

    标签: python compilation pygame png cx-freeze


    【解决方案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 用于图片、声音等包。

    【讨论】:

    • StartGame 和 Background1 在同一个文件夹中。我相当肯定它与所有其他文件一起编译
    • import cx_Freeze executables = [cx_Freeze.Executable("StartGame.py")] cx_Freeze.setup( name="罗密欧与朱丽叶的悲剧故事", options={"build.exe": { "packages":["pygame"], "include_files":["Background1.png"]}}, 可执行文件 = 可执行文件)
    • 这是我的 setup.py,这对我正在做的事情有用吗?
    • @ChrisWinjum 请使用我的答案,先试试这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    相关资源
    最近更新 更多