python - 无法使用 cx_Freeze 进行编译

标签 python windows executable cx-freeze

我制作了一个运行良好的程序,现在我尝试使用 cx_Freeze 编译它,但收到 TypeError: can only concatenate list (not "NoneType") to list 错误。那么我该如何解决这个问题,以便我可以将我的程序正确编译为.exe

我的配置: python 2.7,cx_Freeze 5.1.1

我的程序包含以下模块: os、time、string、random、smtplib、_winreg、requests、pyautogui、subprocess、email、SimpleCV

我的设置文件代码:

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

错误:

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

最佳答案

解决方案是将opencv_ffmpeg342.dll文件放置在可执行文件所在的同一目录中。

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

关于python - 无法使用 cx_Freeze 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52104043/

相关文章:

python - 将 JSON 呈现为 Python 中的目录结构

带有 system.drawing 和可能替代方案的 WIndows 通用应用程序

c++ - cmake 在 Windows 上生成错误,因为它使用\as escape seq

matlab - 从 Octave 中的其他脚本文件运行脚本文件

python - 重新分区 dask 数据帧以减少滚动期间的洗牌

Python 3 - 如何更新字典以在一个键中包含多个值?

c++ - (多操作系统)获取可执行路径

assembly - 可执行部分标题 - 含义和用途?

使用 UTF-8 header 的 Python 2.7 解码错误 : UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3

r - 如何避免 "cannot find -lR"在 Windows 上安装 R 包