【发布时间】:2019-02-25 10:22:09
【问题描述】:
经过大量搜索后,我无法通过 cx_Freeze 解决这个问题。这些问题没有提供有效的解决方案:
cx_Freeze Exe Application closes as soon as opens
How can I bundle other files when using cx_freeze?
这些文件与游戏的其余部分位于同一目录中,当我从我的代码运行游戏时一切正常,唯一的问题是当我尝试从 .exe 文件运行它时。
当我注释掉加载音乐/图像的游戏代码并以此为基础构建时,游戏运行良好。
import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Dan\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Dan\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tk8.6"
includedfiles = ['Background.jpg', 'Background2.jpg', 'bgStream.jpg', 'IntroMus.mp3', 'StreamSong.mp3']
excludes = ['tkinter']
cx_Freeze.setup(
name="The Woodsman's Tale",
version='0.1',
description='TWT Game',
options={'build.exe': {'excludes': [excludes], "packages": ["pygame"],
'included_files': [includedfiles]}},
executables=[cx_Freeze.Executable("startmenu.py")])
【问题讨论】:
-
试试this solution:
includedfiles = [find_data_file('Background.jpg'), find_data_file('Background2.jpg'), etc.。 -
Pygame error: couldn't open 'filename'通常表示路径或文件名不正确。
标签: python pygame jpeg mp3 cx-freeze