Cx_freeze exe无法完全导入docx

时间:2015-05-30 06:42:03

标签: python python-3.x cx-freeze python-docx

我有一个非常大的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]
)

这是我遇到的错误。

enter image description here

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

1 个答案:

答案 0 :(得分:2)

经过一番搞砸之后我终于破解了这个。 docx模块取决于lxml。即使原始.py文件在导入docx时运行完全正常,但在cx_freezing时,您需要通过向包中添加lxml来明确说明依赖关系。