cx_Freeze:找不到文件/目录 icon.gif

Posted

技术标签:

【中文标题】cx_Freeze:找不到文件/目录 icon.gif【英文标题】:cx_Freeze: cannot find file/directory icon.gif 【发布时间】:2014-08-05 12:17:26 【问题描述】:

我正在将 cx_Freeze 与 Python 3.4.1 一起使用,并且我正在尝试从我的一个 Python 程序中创建一个应用程序。不幸的是,运行 setup.py 构建后出现此错误:

cx_Freeze.freezer.ConfigError: cannot find file/directory named icon.gif

这是我的设置文件:

import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == "win32" : base = "Win32GUI"

opts = "include_files": ['icon.gif', "EndingsPerfect.txt", "EndingsPPP.txt", "LatinEnglishPronouns.txt", "1stConj/", "2ndConj/", "3rdConj/", "4thConj/"], "includes": ["re"]

setup(name = "LT",
      version = "1.0",
      description = "Latin verbs",
      author = "Laurence vS",
      options = "build_exe": opts,
      executables = [Executable("latintranslatewithguipyw.pyw", base = base)])

这个错误让我很困惑,因为icon.gif 文件与安装文件位于同一文件夹中。

这是完整的回溯:

C:\Users\Laurence> python "C:\Users\Laurence\Dropbox\Python programs\GUIs\latintr
anslatewithgui\setup.py" build

running build
running build_exe
Traceback (most recent call last):
  File "C:\Users\Laurence\Dropbox\Python programs\GUIs\latintranslatewithgui\set
up.py", line 14, in <module>
    executables = [Executable("latintranslatewithguipyw.pyw", base = base)])
  File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
    distutils.core.setup(**attrs)
  File "C:\Python34\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python34\lib\distutils\command\build.py", line 126, in run
    self.run_command(cmd_name)
  File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 231, in run
    metadata = metadata)
  File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 108, in __init
__
    self._VerifyConfiguration()
  File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 498, in _Verif
yConfiguration
    sourceFileName)
cx_Freeze.freezer.ConfigError: cannot find file/directory named icon.gif

任何帮助将不胜感激。

【问题讨论】:

它会根据您运行它时的位置来查找。在终端使用cd切换到文件所在目录,然后运行python setup.py build 感谢@ThomasK,成功了。 【参考方案1】:

作为答案转发:

相对路径名是相对于您运行的位置,而不是 setup.py 脚本所在的位置。在终端使用cd切换到setup.py所在目录,然后运行python setup.py build

如果由于某种原因不可行,您可以在 setup.py 脚本中使用 os.chdir()

【讨论】:

以上是关于cx_Freeze:找不到文件/目录 icon.gif的主要内容,如果未能解决你的问题,请参考以下文章

cx_Freeze 找不到 QtDesigner 框架

cx_Freeze:Python 错误主脚本。找不到模块错误:没有名为 pygments.lexers.python 的模块

Cx_Freeze 找不到 pkg_resources/*.*'

找不到模块'cx_Freeze__init__'

cx_Freeze 应用程序找不到 tk.tcl

使用 cx_freeze 构建的 Exe 会为所需的包产生“找不到模块”错误