在询问此问题之前已检查其他查询(cx_freeze ImportError when executing file)与我的问题有关,错误是“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)])
我的错误是(http://i.imgur.com/TSVg6Ft.png),我找不到文件“'matplotlib.backends.backend_tkagg'”,请提前告知,提前谢谢
答案 0 :(得分:0)
cx-freeze具有良好的模块分析,但有时会失败。特别是背部和模块。
Matplotlib使用 tkagg (我不确定它是包名)作为后端gui模块。要解决这个问题,您有两种选择:
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"],