0

我有一个非常庞大的 python 脚本,我正在尝试 cx_freeze,但是当我运行可执行文件时,我不断收到相同的错误,它似乎与 docx 模块有关。

我在 Windows 8.1 机器上使用 Python 3.3.5 和 docx 0.7.6-py33。

这是我的设置脚本。

from cx_Freeze import setup, Executable

includefiles = ['logo.ico','db.db','dbloc.bin']
includes = []
excludes = []
packages = ['tkinter','docx','sys', 'sqlite3', 'os', 'hashlib', 'random', 'uuid', 'base64', 'tempfile', 'win32api',
            'winreg', 'ntplib', 'winsound', 'time', 'csv', 'webbrowser', 'inspect','datetime', 'decimal', 'ctypes',
            'win32com.client','operator']

exe = Executable(
# what to build
   script = "NEPOS.py",
   initScript = None,
   base = 'Win32GUI',
   targetName = "Nepos.exe",
   copyDependentFiles = True,
   compress = True,
   appendScriptToExe = True,
   appendScriptToLibrary = True,
   icon = 'Icon.ico'
)

setup(
    name = "MyProgram",
    version = "1.0.0",
    description = 'Description',
    author = "Joe Bloggs",
    author_email = "123@gmail.com",
    options = {"build_exe": {"excludes":excludes,"packages":packages,
      "include_files":includefiles}},
    executables = [exe]
)

这是我得到的错误。

在此处输入图像描述

看起来它很难找到属于 docx 的方法,但是我的源代码调用import docx并且它在安装文件中被列为依赖模块,所以我不确定为什么不包含它们。

4

1 回答 1

2

经过很多混乱,我终于破解了这个。该docx模块依赖于lxml. 即使原始.py文件在刚docx导入的情况下运行得非常好,但当 cx_freezing 时,您需要通过添加lxml到包中来明确声明依赖关系。

于 2015-05-30T11:02:45.013 回答