gpt4 book ai didi

python - 将 PyInstaller 用于 Matplotlib 脚本后出错

转载 作者:行者123 更新时间:2023-12-04 17:23:33 25 4
gpt4 key购买 nike

在我的代码中我使用:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

当我构建 .py 脚本时,一切正常。但是在使用 pyinstaller.exe 获取可执行文件后,出现以下错误:

Traceback (most recent call last):
File "C:\Program Files\Python38\Scripts\excel_to_python.py", line 10, 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 "c:\program files\Python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, 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\\usr\\AppData\\Local\\Temp\\_MEI640402\\matplotlib\\mpl-data\\matplotlibrc'
[62044] Failed to execute script mpl_script

我尝试重新安装 matplotlib 和 pyinstaller,但还是一样。

最佳答案

  1. 安装 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 , 然后
  2. 使用 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 ft2fontmatplotlib import ft2font .那里有几个建议安装 Visual C++ Redistributable Package 的答案,而这实际上是唯一有用的东西。

关于python - 将 PyInstaller 用于 Matplotlib 脚本后出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64859164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com