CX-冻结未能包括模块即使当具体包括(cx-freeze fails to include modu

2019-06-23 17:54发布

我试图使用CX-冻结创建我的应用程序(该Spye Python的引擎,静态自足分布www.spye.dk ),然而,当我运行CX-冻结,它说:

Missing modules:
? _md5 imported from hashlib
? _scproxy imported from urllib
? _sha imported from hashlib
? _sha256 imported from hashlib
? _sha512 imported from hashlib
? _subprocess imported from subprocess
? configparser imported from apport.fileutils
? usercustomize imported from site

这是我的setup.py:

#!/usr/bin/env python
from cx_Freeze import setup, Executable

includes = ["hashlib", "urllib", "subprocess", "fileutils", "site"]
includes += ["BaseHTTPServer", "cgi", "cgitb", "fcntl", "getopt", "httplib", "inspect", "json", "math", "operator", "os", "os,", "psycopg2", "re", "smtplib", "socket", "SocketServer", "spye", "spye.config", "spye.config.file", "spye.config.merge", "spye.config.section", "spye.editor", "spye.framework", "spye.frontend", "spye.frontend.cgi", "spye.frontend.http", "spye.input", "spye.output", "spye.output.console", "spye.output.stdout", "spye.pluginsystem", "spye.presentation", "spye.util.html", "spye.util.rpc", "ssl", "stat,", "struct", "subprocess", "sys", "termios", "time", "traceback", "tty", "urllib2", "urlparse", "uuid"]

includefiles=[]
excludes = []
packages = []
target = Executable(
    # what to build
    script = "spye-exe",
    initScript = None,
    #base = 'Win32GUI',
    targetDir = r"dist",
    targetName = "spye.exe",
    compress = True,
    copyDependentFiles = True,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = None
    )

setup(
    version = "0.1",
    description = "No Description",
    author = "No Author",
    name = "cx_Freeze Sample File",

    options = {"build_exe": {"includes": includes,
                 "excludes": excludes,
                 "packages": packages
                 #"path": path
                 }
           },

    executables = [target]
    )

请注意,我明确指定缺少的模块中包括列表。

我该如何解决?

Answer 1:

缺少模块不一定是一个问题:很多模块尝试不同的进口,以适应不同的平台或不同版本的Python。 在subprocess ,例如,你可以找到这样的代码:

if mswindows:
    ...
    import _subprocess

cx_Freeze不知道这一点,所以它会试图找到_subprocess在Linux / Mac上为好,并报告为缺失。 指定它们includes不会改变任何东西,因为它试图将它们包括,但无法找到他们。

它应该反正建一个文件,所以尝试运行,看它是否工作。



Answer 2:

我想,你不能简单地+=上列出。

你或许应该使用列表法extend -否则原始列表将不会被修改:

includes.extend(["BaseHTTPServer", "<rest of your modules>"])

编辑:(感谢@ThomasK)

+=正常工作-我只用了一个在线Python解释器未正常工作。 (我没有蟒蛇安装在我的Windows安装,所以我不得不在网上查询)。



文章来源: cx-freeze fails to include modules even when included specifically