编程语言
首页 > 编程语言> > python-cx_Freeze:找不到文件/目录icon.gif

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

作者:互联网

我正在将cx_Freeze与Python 3.4.1结合使用,并且试图从我的Python程序之一创建应用程序.不幸的是,在运行setup.py build之后,我得到了这个错误:

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

任何帮助,将不胜感激.

解决方法:

重新发布作为答案:

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

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

标签:python-3-x,cx-freeze,python
来源: https://codeday.me/bug/20191029/1958760.html