即使专门包含cx-freeze,也无法包含模块 [英] cx-freeze fails to include modules even when included specifically
问题描述
我正在尝试使用cx-freeze创建我的应用程序的静态自包含发行版(The Spye Python Engine, www .spye.dk ),但是,当我运行cx-freeze时,它说:
I am trying to use cx-freeze to create a static self-contained distribution of my app (The Spye Python Engine, www.spye.dk), however, when I run cx-freeze, it says:
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:
This is my 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]
)
请注意,我在包含列表中明确指定了缺少的模块。
Please note that I clearly specify the missing modules in the includes list.
我该如何解决?
推荐答案
缺少模块一定是一个问题:许多模块尝试不同的导入以适应不同的平台或不同版本的Python。例如,在子流程
中,您可以找到以下代码:
Missing modules aren't necessarily a problem: a lot of modules try different imports to accommodate different platforms or different versions of Python. In subprocess
, for example, you can find this code:
if mswindows:
...
import _subprocess
cx_Freeze不知道这样,因此它将尝试在Linux / Mac上也找到 _subprocess
,并将其报告为丢失。在 includes
中指定它们不会更改任何内容,因为它试图包含它们,但找不到它们。
cx_Freeze doesn't know about this, so it will try to find _subprocess
on Linux/Mac as well, and report it as missing. Specifying them in includes
doesn't change anything, because it's trying to include them, but unable to find them.
无论如何,它都应该建立一个文件,因此请尝试运行该文件并查看其是否有效。
It should build a file anyway, so try running that and seeing if it works.
这篇关于即使专门包含cx-freeze,也无法包含模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!