我的可执行脚本使用的包很少依赖于xlrd模块。因此,我尝试使用include选项将此模块包括在安装脚本中,如图所示。但是,当runnery.py调用包模块时,模块无法导入xlrd,尽管xlrd文件存在于library.zip文件中。from cx_Freeze import setup, Executable
import xlrd
buildOptions = dict(
compressed = True,
optimize=2,
path=sys.path+[".\\uitls", “.\\supported”],
include_files=[“Doc"],
includes=[“xlrd”, "win32com"],
packages=["utils", ”supported"],
append_script_to_exe=True,
copy_dependent_files=True,
)
setup(
name = "TestExecutable",
version = "0.1",
options = dict(build_exe = buildOptions),
executables = [Executable(
script=r".\\codebase\\ runner.py",
icon=".\\icon.ico",
base="Win32GUI")]
)
如果我尝试在runner.py中导入xlrd,它就能够导入它。我不知道在这种情况下出了什么问题,因为依赖包无法导入xlrd。有没有什么选择是我错过了还是我做错了什么?
更新:
我发现依赖包是通过生成一个进程来调用的,因此它创建了一个新的环境,其中没有xlrd模块,并且不知道包含它的library.zip。所以现在,我是否有可能使xlrd模块从zip文件中对包可用,即使它是通过spwaning新进程运行的?
谨致问候