我使用tkinter和winsound在Python中构建了一个简单的音板。音板使用一些.gif和.wav数据文件,我将它们包含在与python脚本本身相同的目录中。我使用cx_Freeze编写了以下setup.py文件:
import sys
from cx_Freeze import Executable, setup
build_exe_options = {'packages':['winsound', 'tkinter'], 'include_files':['battle.gif', 'Battle.wav', 'flag.gif', 'icon.ico', 'ocean.gif', 'Ocean.wav', 'shanty.gif', 'Shanty.wav', 'tavern.gif', 'Tavern.wav']}
base = None
if sys.platform == "win32":
base = 'Win32GUI'
setup(name='Savage Worlds Soundboard',
version='0.1',
description='Soundboard for Pirates of the Spanish Main campaign',
options = {'build.exe':build_exe_options},
executables = [Executable("Savage_Worlds_Soundboard.py", base=base)]
)
当我在命令提示符下使用python setup.py构建程序时,它会在目录中正常创建一个构建文件夹。但是,当我打开C:x \ build \ exe.win-amd64-3.4 \ Savage_Worlds_Soundboard(可执行文件)时,我收到以下错误:
cx_Freeze: Python error in main script
---------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "Savage_Worlds_Soundboard.py", line 5, in <module>
File "C:\Python34\lib\tkinter\__init__.py", line 3421, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python34\lib\tkinter\__init__.py", line 3377, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "ocean.gif": no such file or directory
有什么想法吗?在我看来,cx_Freeze没有包含我在setup.py中指定的其他数据文件。也许我错误地写了安装文件?
答案 0 :(得分:0)
您需要将图像移动到构建目录,以便可执行文件可以找到它们。我怀疑cx_Freeze会将图像打包成可执行文件。