Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: DLL load failed with Matplotlib 3.3.1 on Windows #18292

Closed
eamars opened this issue Aug 19, 2020 · 17 comments · Fixed by #18322
Closed

ImportError: DLL load failed with Matplotlib 3.3.1 on Windows #18292

eamars opened this issue Aug 19, 2020 · 17 comments · Fixed by #18322
Milestone

Comments

@eamars
Copy link

eamars commented Aug 19, 2020

Bug report

Bug summary

On some Windows machines (including Windows 10 and Windows 7), we experienced ImportError: DLL load failed: The specific module could not be found after upgrading from Matplotlib 3.3.0 to 3.3.1.

Code for reproduction

import matplotlib would trigger the import error while trying to import ft2font.

Actual outcome

In [1]: import matplotlib
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-0484cd13f94d> in <module>
----> 1 import matplotlib

c:\users\nzlab\envs\nta-1465\lib\site-packages\matplotlib\__init__.py in <module>
    172
    173
--> 174 _check_versions()
    175
    176

c:\users\nzlab\envs\nta-1465\lib\site-packages\matplotlib\__init__.py in _check_versions()
    157     # Quickfix to ensure Microsoft Visual C++ redistributable
    158     # DLLs are loaded before importing kiwisolver
--> 159     from . import ft2font
    160
    161     for modname, minver in [

ImportError: DLL load failed: The specified module could not be found.

Expected outcome

No error should be presented.

Matplotlib version

  • Operating system: Windows 7 (64bit), Windows 10 (64bit)
  • Matplotlib version: 3.3.1
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: Python 3.7.6
  • Jupyter version (if applicable):
  • Other libraries: Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.27.29016 NOT INSTALLED

**Further diagnose shows: **

  • ft2font.cp37-win_amd64.pyd (Matplotlib 3.3.0) links VCRUNTIME140.dll
  • ft2font.cp37-win_amd64.pyd (Matplotlib 3.3.1) links VCRUNTIME140_1.dll

Those computers which have DLL load failed don't have VCRUNTIME140_1.dll in DLL search path.

Solution
Installing the latest Visual Studio 2015, 2019 and 2019 redistributable should address the issue.

Question
Is changing in VC++ API (from 14 to 14.1) an intentional move on Matplotlib 3.3.1 for Windows release? If so, should the VC++ dependency to be added to Installation Guide?

@tacaswell
Copy link
Member

I don't think this was an intentional change on our part, but fallout from a change in how we built the wheels (we changed from relying on @cgohlke to building the wheels with GH actions).

@eamars Can you verify that the wheels from https://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib do work for you? If so we can upload those while we try and sort out what we are doing wrong.

@tacaswell tacaswell added this to the v3.3.2 milestone Aug 19, 2020
@eamars
Copy link
Author

eamars commented Aug 19, 2020

Thanks @tacaswell , matplotlib‑3.3.1‑cp37‑cp37m‑win_amd64.whl as provided in https://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib invokes VCRUNTIME140.dll instead.

I guess the build environment might have a different version of VC++ installed.

@QuLogic
Copy link
Member

QuLogic commented Aug 22, 2020

Please try the wheels from here. I checked them with objdump and they don't seem to depend on VCRUNTIME140_1.dll any more.

@QuLogic
Copy link
Member

QuLogic commented Aug 24, 2020

I pulled the wheels from @cgohlke, updated the build number, and am in the process of uploading those. You should be able to re-install matplotlib 3.3.1 after that (maybe in about 10 minutes) and not run into this issue.

@mkunzBGC
Copy link

mkunzBGC commented Mar 8, 2021

This issue is present again with matplotlib 3.3.2, 3.3.3 and 3.3.4. . matplotlib 3.3.0 3.3.1 work.

System

  • Windows 10 Pro freshly installed in a virtual machine
  • Python 3.8.8 32-bit from python.org
  • matplotlib installed using py -m pip install matplotlib[==<version>]

Traceback

C:\Users\standarduser>py
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python38-32bit\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
    _check_versions()
  File "C:\Python38-32bit\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.

@mivanit
Copy link

mivanit commented Jun 23, 2021

I have a similar error

OS: Microsoft Windows 10 Pro 
  version: 10.0.19042
pip: 21.1.2
python: 3.9
matplotlib: 3.4.2

Error message:

Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\__init__.py", line 107, in <module>
    from . import _api, cbook, docstring, rcsetup
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\rcsetup.py", line 26, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\colors.py", line 82, in <module>
    from matplotlib import _api, cbook, scale
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\scale.py", line 18, in <module>
    from matplotlib.ticker import (
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\ticker.py", line 179, in <module>
    from matplotlib import transforms as mtransforms
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\transforms.py", line 46, in <module>
    from matplotlib._path import (
ImportError: DLL load failed while importing _path: The specified module could not be found.

EDIT: matplotlib 3.3.1 works, 3.3.4 does not.

@tacaswell
Copy link
Member

This seems like an installation issue, please try recreating your virtual env.

@vamsi1961
Copy link

I have a similar error

OS: Microsoft Windows 10 Pro 
  version: 10.0.19042
pip: 21.1.2
python: 3.9
matplotlib: 3.4.2

Error message:

Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\__init__.py", line 107, in <module>
    from . import _api, cbook, docstring, rcsetup
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\rcsetup.py", line 26, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\colors.py", line 82, in <module>
    from matplotlib import _api, cbook, scale
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\scale.py", line 18, in <module>
    from matplotlib.ticker import (
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\ticker.py", line 179, in <module>
    from matplotlib import transforms as mtransforms
  File "C:\Program Files\Python39\lib\site-packages\matplotlib\transforms.py", line 46, in <module>
    from matplotlib._path import (
ImportError: DLL load failed while importing _path: The specified module could not be found.

EDIT: matplotlib 3.3.1 works, 3.3.4 does not

is issue resolved

@jklymak
Copy link
Member

jklymak commented Dec 24, 2022

Issue is closed because we cannot reproduce. If you can reproduce with a clean environment and installation please open a new issue with all the steps taken so we can reproduce. Otherwise please take installation help questions to https://discourse.matplotlib.org thanks

@QuLogic
Copy link
Member

QuLogic commented Dec 24, 2022

If you're still seeing something similar, it's probably a duplicate of #24704.

@xtofl
Copy link

xtofl commented Jan 24, 2023

I reproduced the issue on a windows machine (windows 10 IoT, build 1809 build 17763.3887)

Python version 3.10.9

Using Sysinternals' "Process Monitor" (https://learn.microsoft.com/en-us/sysinternals/downloads/process-utilities), I can see
that python looks for MSCVP140.dll in four locations:

  1. \site-packages\matplotlib\
  2. "C:\Program Files\Python310" (o why?)
  3. \site-packages\numpy.libs
  4. C:\Windows\System32

I was hoping that pip install msvc-runtime would help, since it adds MSVCP140.dll into the <venv>\Scripts directory, which is on the PATH. But it does not: the locations searched for said dll are limited

---8<-------logging ------------------------------------------------------

$ python -m venv matplotlib-msvcp140.dll
$ source matplotlib-msvcp140.dll/Scripts/activate
(matplotlib-msvcp140.dll) $ pip install matplotlib==3.6.3
Collecting matplotlib==3.6.3
  Downloading matplotlib-3.6.3-cp310-cp310-win_amd64.whl (7.2 MB)
     ---------------------------------------- 7.2/7.2 MB 11.8 MB/s eta 0:00:00
Collecting numpy>=1.19
  Downloading numpy-1.24.1-cp310-cp310-win_amd64.whl (14.8 MB)
     --------------------------------------- 14.8/14.8 MB 13.1 MB/s eta 0:00:00
Collecting packaging>=20.0
  Using cached packaging-23.0-py3-none-any.whl (42 kB)
Collecting contourpy>=1.0.1
  Downloading contourpy-1.0.7-cp310-cp310-win_amd64.whl (162 kB)
     -------------------------------------- 163.0/163.0 kB 9.5 MB/s eta 0:00:00
Collecting python-dateutil>=2.7
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ------------------------------------- 247.7/247.7 kB 14.8 MB/s eta 0:00:00
Collecting pillow>=6.2.0
  Downloading Pillow-9.4.0-cp310-cp310-win_amd64.whl (2.5 MB)
     ---------------------------------------- 2.5/2.5 MB 13.1 MB/s eta 0:00:00
Collecting kiwisolver>=1.0.1
  Downloading kiwisolver-1.4.4-cp310-cp310-win_amd64.whl (55 kB)
     ---------------------------------------- 55.3/55.3 kB 2.8 MB/s eta 0:00:00
Collecting cycler>=0.10
  Downloading cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting pyparsing>=2.2.1
  Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
     ---------------------------------------- 98.3/98.3 kB 5.5 MB/s eta 0:00:00
Collecting fonttools>=4.22.0
  Downloading fonttools-4.38.0-py3-none-any.whl (965 kB)
     ------------------------------------- 965.4/965.4 kB 12.2 MB/s eta 0:00:00
Collecting six>=1.5
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pyparsing, pillow, packaging, numpy, kiwisolver, fonttools, cycler, python-dateutil, contourpy, matplotlib
Successfully installed contourpy-1.0.7 cycler-0.11.0 fonttools-4.38.0 kiwisolver-1.4.4 matplotlib-3.6.3 numpy-1.24.1 packaging-23.0 pillow-9.4.0 pyparsing-3.0.9 python-dateutil-2.8.2 six-1.16.0

(matplotlib-msvcp140.dll) $
(matplotlib-msvcp140.dll) $ python -c "import matplotlib"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\__init__.py", line 113, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\colors.py", line 56, in <module>
    from matplotlib import _api, _cm, cbook, scale
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\scale.py", line 22, in <module>
    from matplotlib.ticker import (
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\ticker.py", line 138, in <module>
    from matplotlib import transforms as mtransforms
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\transforms.py", line 49, in <module>
    from matplotlib._path import (
ImportError: DLL load failed while importing _path: The specified module could not be found.
(matplotlib-msvcp140.dll) $ python -c "import matplotlib"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\__init__.py", line 113, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\colors.py", line 56, in <module>
    from matplotlib import _api, _cm, cbook, scale
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\scale.py", line 22, in <module>
    from matplotlib.ticker import (
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\ticker.py", line 138, in <module>
    from matplotlib import transforms as mtransforms
  File "C:\Users\MXadmin\matplotlib-msvcp140.dll\lib\site-packages\matplotlib\transforms.py", line 49, in <module>
    from matplotlib._path import (
ImportError: DLL load failed while importing _path: The specified module could not be found.
(matplotlib-msvcp140.dll) 

@xtofl
Copy link

xtofl commented Jan 24, 2023

Lots of windows programs do install the MSVC runtime libraries. This may explain why the issue can't be reproduced on a lot of systems. Copying the missing dll to e.g. C:\Windows\System32 makes it go away.

@tacaswell
Copy link
Member

@xtofl Can you please try installing the nightly wheels: https://matplotlib.org/stable/users/installing/index.html#installing-a-nightly-build We have made changes to how the wheels are built that may solve this problem.

@xtofl
Copy link

xtofl commented Jan 25, 2023

Sure. Has the dll search path changed, or has the dll been shipped with the wheel? Could you point me to those changes?

@QuLogic
Copy link
Member

QuLogic commented Jan 25, 2023

They are shipped in the wheel. #24724

@xtofl
Copy link

xtofl commented Jan 25, 2023

Good news: that version does not show the problem (I had to remember removing the dll from my C:\Windows\System32 folder first).

When looking through Process Monitor, I can see that msvcp140.dll is found in <venv>/site-packages/matplotlib.libs/msvcp140.dll. 🥳

@xtiansimon
Copy link

xtiansimon commented Feb 5, 2023

@xtofl Can you please try installing the nightly wheels

That worked for me!

  • Windows 10 Pro v22H3 Build 19045.2486,
  • Miniconda3 (4.12) Windows 32-bit 3.9

I tried several of the top Google search results before I found this ticket:

  1. conda install freetype --force-reinstall
  2. downgrade to Python 3.7 & matplotlib 3.03
  3. Installing MS Visual C++ redistributable 2019
  4. pip install msvc-runtime

QuLogic added a commit to QuLogic/matplotlib that referenced this issue Aug 15, 2024
As of matplotlib#28687, our extensions depend on `VCRUNTIME140_1.dll`, and this
was allowed because Python 3.8+ started shipping that file. The original
report in matplotlib#18292 was for Python 3.7, which didn't ship the DLL, but we
require Python 3.10 now, so it's safe again.

Since we can use that dependency, there's no need to disable the option
that started requiring it in the first place. As noted in the original
blog post [1], this will make our extensions smaller, and slightly
faster.

[1] https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants