【问题标题】:cx_Freeze not including specified filescx_Freeze 不包括指定文件
【发布时间】:2016-06-18 21:12:10
【问题描述】:

我用 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 build 构建程序时,它通常会在目录中创建一个构建文件夹。但是,当我打开 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 中指定的其他数据文件。可能是我的设置文件写错了?

【问题讨论】:

  • 只是猜测,但您可能需要将图像移动到构建目录,以便可执行文件可以找到它们。我怀疑 cx_Freeze 会将图像打包到可执行文件中。
  • 这行得通……我觉得自己很愚蠢。谢谢!您可以将此作为答案发布。
  • 不用担心,我在使用 wxWidgets 和 C++ 构建时遇到了同样的麻烦 :)

标签: python cx-freeze


【解决方案1】:

您需要将图像移动到构建目录,以便可执行文件可以找到它们。我怀疑 cx_Freeze 会将图像打包到可执行文件中。

【讨论】:

    猜你喜欢
    • 2017-06-27
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多