5

我正在尝试使用 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]
    )

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

我该如何解决?

4

2 回答 2

0

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

if mswindows:
    ...
    import _subprocess

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

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

于 2012-04-18T10:22:06.643 回答
-1

我猜,你不能简单地+=放在名单上。

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

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

编辑:(感谢@ThomasK)

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

于 2012-04-18T08:01:27.767 回答