Skip to content Skip to sidebar Skip to footer

Error After Using Pyinstaller For Script With Matplotlib

In my code I am using: import matplotlib.pyplot as plt import matplotlib.image as mpimg When I build the .py script, everything works fine. But after using the pyinstaller.exe to

Solution 1:

  1. Install the Visual C++ Redistributable Package (vc_redist.x64.exe or vc_redist.x86.exe depending on your Windows). You can find it here: the latest supported visual c downloads, here: vc_redist.x64 or here: vc_redist.x86, then
  2. rebuild your executable with pyinstaller.

Analysis

I had the same error in Windows 7 64-bit with Python 3.8.7:

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 calllast):
  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 toexecute script MyTool

I rebuilt the executable with debug level as per pyinstaller-python:

pyinstaller --onefile --log-level=DEBUG MyTool.py

In the building traces I saw the matplotlib Traceback below:

18885INFO: Loadingmodule 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.
19108INFO: Loadingmodule 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.

That led me to: dll load failed while importing ft2font, matplotlib cant load ft2font and matplotlib import ft2font. There were several answers there which suggested installing Visual C++ Redistributable Package, and that was actually the only thing that helped.

Post a Comment for "Error After Using Pyinstaller For Script With Matplotlib"