【发布时间】:2020-11-24 11:34:06
【问题描述】:
上下文
我正在尝试使用cx_freeze 构建python tkinter 应用程序,并且成功构建了.exe。这是我的 setup.py:
import sys
from cx_Freeze import setup, Executable
version = "0.7.6"
author = "Me"
base = None
if sys.platform == "win32":
base = "Win32GUI"
build_exe_options = {"include_files": ["assets/", "files/"], "excludes": ["matplotlib.tests", "numpy.random._examples"],
"include_msvcr": True}
setup(
name="Application",
version=version,
description=f"Application {version}",
author=author,
options={"build_exe": build_exe_options},
executables=[Executable(script="main.py", base=base, targetName="App.exe", icon="assets/Logo.ico")]
)
问题的识别
但是,我在 Python 代码中使用的某些库,例如 matplotlib,只能使用 Visual Studio 2015 或更高版本进行编译(请参阅 documentation)。我的计算机上有 Visual Studio 2019,所以一切正常,但我尝试在另一台只有 Microsoft Visual C++ 2010 Redistributable 包(我猜是 2010 编译工具)的 Windows 计算机上运行该应用程序,并且该应用程序在启动前崩溃了这个主要错误:
ImportError: DLL load failed while importing ft2font: 找不到指定的模块。
根据here 的讨论,我认为此错误意味着不满足 Visual Studio 要求(即 2015 年或更高版本),并且如本文末尾所述discussion 所示,matplotlib 轮不包括 C++ 运行时 DLL对于版本 > 3.3.0。在问我的问题之前,我必须说我对 python 库是如何编译的或轮子是什么的理解非常有限,我什至不知道我构建的应用程序的编译涉及哪些 C++ 运行时 DLL。
问题
如何在我的应用程序中包含 Microsoft Visual C++ 2015 Redistributable 包(假设这是合法的)?
对我来说一个简单的解决方案是在我的项目中包含所有必要的依赖项,而无需用户在其计算机上安装 Visual Studio C++ 2015+ 版本,所以如果您对如何使用 cx_freeze 甚至我可能会研究一些其他工具,在此先感谢您的帮助。
保罗
P.S:如您所见,我尝试了 build_exe_options 中的 "include_msvcr" 键,但这并没有解决我的问题(另外我认为 msvcp.dll 默认包含在内)
更新
我手动将vcruntime140_1.dll、msvcp140_1.dll放入目录中,应用程序正在启动,但是窗口显示不正确,没有出现框架,所以问题还没有解决。
【问题讨论】:
标签: python windows visual-c++ cx-freeze