-
安装 Visual C++ Redistributable Package(vc_redist.x64.exe 或 vc_redist.x86.exe,具体取决于您的 Windows)。你可以在这里找到它:the latest supported visual c downloads,在这里:vc_redist.x64 或在这里:vc_redist.x86,然后
-
使用 pyinstaller重建您的可执行文件。
分析
我在带有 Python 3.8.7 的 Windows 7 64 位中遇到了同样的错误:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\w\Desktop\1\dist>MyTool.exe
Traceback (most recent call last):
File "MyTool.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "matplotlib\__init__.py", line 913, in <module>
File "matplotlib\__init__.py", line 812, in _rc_params_in_file
File "contextlib.py", line 113, in __enter__
File "matplotlib\__init__.py", line 790, in _open_file_or_url
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\w\\AppData\\Local\\Temp\\_MEI17002\\matplotlib\\mpl-data\\matplotlibrc'
[916] Failed to execute script MyTool
我按照pyinstaller-python 重建了具有调试级别的可执行文件:
pyinstaller --onefile --log-level=DEBUG MyTool.py
在构建跟踪中,我看到了下面的 matplotlib Traceback:
18885 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'c:\\users\\w\\appdata\\local\\programs\\python\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\w\appdata\local\programs\python\python38\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
_check_versions()
File "c:\users\w\appdata\local\programs\python\python38\lib\site-packages\matplotlib\__init__.py", line 159, in _check_versions
from . import ft2font
ImportError: DLL load failed while importing ft2font: The specified module could not be found.
19108 INFO: Loading module hook 'hook-matplotlib.py' from 'c:\\users\\w\\appdata\\local\\programs\\python\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\w\appdata\local\programs\python\python38\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
_check_versions()
File "c:\users\w\appdata\local\programs\python\python38\lib\site-packages\matplotlib\__init__.py", line 159, in _check_versions
from . import ft2font
ImportError: DLL load failed while importing ft2font: The specified module could not be found.
这导致我:dll load failed while importing ft2font、matplotlib cant load ft2font 和 matplotlib import ft2font。那里有几个答案建议安装 Visual C++ Redistributable Package,这实际上是唯一有帮助的。