即使具体包含,cx-freeze也无法包含模块

时间:2012-04-18 07:55:29

标签: python freeze cx-freeze

我正在尝试使用cx-freeze来创建我的应用程序的静态自包含分发(The Spye Python Engine,www.spye.dk),但是,当我运行cx-freeze时,它说:

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

请注意,我在包含列表中明确指出了缺少的模块。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

缺少模块不一定是个问题:许多模块尝试不同的导入以适应不同的平台或不同版本的Python。例如,在subprocess中,您可以找到以下代码:

if mswindows:
    ...
    import _subprocess

cx_Freeze不知道这一点,所以它也会尝试在Linux / Mac上找到_subprocess,并将其报告为缺失。在includes中指定它们不会改变任何内容,因为它试图包含它们,但无法找到它们。

无论如何它应该构建一个文件,所以尝试运行它并查看它是否有效。

答案 1 :(得分:-1)

我想,你不能简单地在列表上+=

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

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

编辑:(感谢@ThomasK)

+=工作正常 - 我只有一个无法正常工作的在线Python解释器。 (我的Windows安装上没有安装python,所以我必须在线检查。)