Cx_freeze exe无法完全导入docx [英] Cx_freeze exe failing to completely import docx

查看:85
本文介绍了Cx_freeze exe无法完全导入docx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我在Windows 8.1计算机上使用docx 0.7.6-py33的Python 3.3.5。

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

这是我的安装脚本。 / p>

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

这是我遇到的错误。

它看起来像是在查找属于docx的方法时遇到了麻烦,但是我的源代码调用 import docx ,它在安装文件中被列为相关模块,所以我不确定为什么

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.

推荐答案

经过一番混乱之后,我终于破解了这个问题。 docx 模块取决于 lxml 。即使原始的 .py 文件仅导入 docx 即可运行得很好,但是当cx_freezing时,您需要明确声明依赖项通过将 lxml 添加到软件包中。

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.

这篇关于Cx_freeze exe无法完全导入docx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆