Ghantey
Ghantey

Reputation: 636

Cannot compile with cx_Freeze

I made a program which worked fine and now I tried to compile it with cx_Freeze but got TypeError: can only concatenate list (not "NoneType") to list error. So how can I fix this problem so that I can compile my program correctly to .exe

My configuration: python 2.7, cx_Freeze 5.1.1

My program contains following modules: os, time, string, random, smtplib, _winreg, requests, pyautogui, subprocess, email, SimpleCV

My setup file code:

import sys
from cx_Freeze import setup, Executable


company_name = 'My own company'
product_name = 'Program'

sys.setrecursionlimit(5000)

bdist_msi_options = {
    'add_to_path': False,
    'initial_target_dir': r'[C:\Program Files (x86)]\%s\%s' % (company_name, product_name),
    }

path = sys.path
build_exe_options = {
"path": path,
"icon": "myicon.ico"}

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

exe = Executable(script='My_program.py',
                 base=base,
                 icon='myicon.ico',
                )

setup(name = "My program",
      version = "1.1",
      description = "This is my first program",
      executables = [exe],
      options = {'bdist_msi': bdist_msi_options})

Error:

Traceback (most recent call last):
  File "setup.py", line 33, in <module>
    options = {'bdist_msi': bdist_msi_options})
  File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
    distutils.core.setup(**attrs)
  File "C:\Python27\lib\distutils\core.py", line 151, in setup
    dist.run_commands()
  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\distutils\command\build.py", line 127, in run
    self.run_command(cmd_name)
  File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 219, in run
    freezer.Freeze()
  File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 623, in Freeze
    self._WriteModules(fileName, self.finder)
  File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 600, in _WriteModules
    path = os.pathsep.join([origPath] + module.parent.path)
TypeError: can only concatenate list (not "NoneType") to list

Upvotes: 1

Views: 2649

Answers (2)

Ghantey
Ghantey

Reputation: 636

The solution is placing opencv_ffmpeg342.dll file in the same directory where the executable file is located.

opencv_ffmpeg342.dll is located at [Place where you have installed python] \ Lib \ site-packages \ cv2

Upvotes: 1

jpeg
jpeg

Reputation: 2461

The module cv2 causes an infinite recursion with cx_Freeze, see cx_Freeze - opencv compatibility

Remove the statement

sys.setrecursionlimit(5000)

from your setup script. You should then see the following error

module = self._modules[name] = Module(name)
RuntimeError: maximum recursion depth exceeded while calling a Python object

If you can live without using cv2, you can exclude it (see below how to do that).

I guess a further problem could be that SimpleCV requires numpy and scipy, and these packages need to be included explicitly in the cx_Freeze setup script.

Altogether, try to modify your build_exe_options as follows:

build_exe_options = {"path": path,
                     "include_files": ["myicon.ico"],
                     "packages": ["numpy", "scipy"],
                     "excludes": ["scipy.spatial.cKDTree", "cv2"]}

The path option is actually not necessary because the default value is sys.path.

The icon option does not exist, I guess you intended to use include_files. This option might not be necessary if you don't use the icon file in the program itself.

Don't forget to add the build_exe_options to the setupcommand:

setup(name = "My program",
      version = "1.1",
      description = "This is my first program",
      executables = [exe],
      options = {'build_exe': build_exe_options,
                 'bdist_msi': bdist_msi_options})

On my Linux machine, I still get errors caused by matplotlib after these modifications (see cx_freeze error with matplotlib data), but they seem specific to Linux so under Windows it might work for you.

Upvotes: 0

Related Questions