Search code examples
pythonpython-3.xcx-freeze

cx_Freeze: cannot find file/directory icon.gif


I am using cx_Freeze with Python 3.4.1 and I am trying to create an application from one of my Python programs. Unfortunately, I get this error after running the setup.py build:

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

Here is my setup file:

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)])

This error confuses me since the icon.gif file is in the same folder as the setup file.

Here is the full traceback:

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

Any help would be appreciated.


Solution

  • Reposting as an answer:

    Relative path names are found relative to where you run from, not where the the setup.py script is. Use cd in the terminal to change to the directory where setup.py is, and then run python setup.py build.

    If that's not practical for some reason, you could use os.chdir() inside the setup.py script.