使用cx_freeze创建的Python可执行文件无法打开的错误
在问这个问题之前,我查看了其他相关的问题(cx_freeze执行文件时的ImportError),那个问题和我的情况有点像,错误是“DLL加载失败”,但我这边的错误是“没有这个模块”。
我的问题是 - 我用cx_freeze创建了一个Python可执行文件,但当我打开Main.exe文件时,应用程序出现了Traceback错误。
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"optimize": 2,
"includes": [],
"compressed": True,
"copy_dependent_files": True,
"create_shared_zip": False,
"append_script_to_exe": True,
"include_in_shared_zip": False,
"include_files":[('vPlot.ui'),
('vPlot.py'),
('company.jpg')],
"include_msvcr": True,
"packages": [],
}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "plcTest",
description = "plcTest!",
options = {"build_exe": build_exe_options},
executables = [Executable("Main.py",
base=base,
copyDependentFiles=True,
appendScriptToExe=True)])
我的错误是(https://i.stack.imgur.com/w1oLc.png),我找不到文件“'matplotlib.backends.backend_tkagg'”,请给我一些建议,提前谢谢你。
1 个回答
0
cx-freeze在分析模块方面表现不错,但有时候会出现问题,特别是对于后端和模块的处理。
Matplotlib使用的是tkagg(我不太确定这是不是包的名字)作为图形界面的后端模块。要解决这个问题,你有两个选择:
1- 在你的代码中某个地方导入缺失的包。
2- 将包的名字作为参数传递给cx-freeze。
举个例子:我是在命令行中使用cx-freeze的。
cxfreeze FooMain.py --include-module=simplejson, lxml # FooMain.py my main script
补充:使用python的build_exe_options。
"packages": ["simplejson", "lxml"],