Cx_freeze exe failing to completely import docx

孤人 提交于 2019-12-25 14:13:51

问题


I have a pretty hefty python script that I'm trying to cx_freeze, however when I run the executable file I keep getting the same error and it appears to be related to the docx module.

I'm using Python 3.3.5 with docx 0.7.6-py33 on a Windows 8.1 machine.

This is my setup script.

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

This is the error I'm getting.

It looks like it is having trouble finding methods that belong to docx, but my source code calls import docx and it is listed as a dependent module in the setup file so I'm not sure why they aren't being included.


回答1:


After a LOT of messing about I've finally cracked this. The docx module is dependent on lxml. Even though the raw .py file runs perfectly fine with just docx imported, when cx_freezing you need to explicitly state the dependency by adding lxml to the packages.



来源:https://stackoverflow.com/questions/30543169/cx-freeze-exe-failing-to-completely-import-docx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!