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

DLL load failed on one machine #14558

Closed
AlexP11223 opened this issue Jun 15, 2019 · 23 comments
Closed

DLL load failed on one machine #14558

AlexP11223 opened this issue Jun 15, 2019 · 23 comments

Comments

@AlexP11223
Copy link

Bug report

Bug summary

ImportError: DLL load failed: The specified module could not be found when importing matplotlib. On another PC it works fine, the same Python 3.7.3 and packages.

Code for reproduction

import matplotlib

Outcome

C:\Users\user1\Downloads>poetry new mpl
Created package mpl in mpl

C:\Users\user1\Downloads>cd mpl

C:\Users\user1\Downloads\mpl>poetry add matplotlib
Creating virtualenv mpl-py3.7 in C:\Users\user1\AppData\Local\pypoetry\Cache\virtualenvs
Using version ^3.1 for matplotlib

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 16 installs, 0 updates, 0 removals

  - Installing zipp (0.5.1)
  - Installing importlib-metadata (0.18)
  - Installing six (1.12.0)
  - Installing atomicwrites (1.3.0)
  - Installing attrs (19.1.0)
  - Installing colorama (0.4.1)
  - Installing cycler (0.10.0)
  - Installing kiwisolver (1.1.0)
  - Installing more-itertools (7.0.0)
  - Installing numpy (1.16.4)
  - Installing pluggy (0.12.0)
  - Installing py (1.8.0)
  - Installing pyparsing (2.4.0)
  - Installing python-dateutil (2.8.0)
  - Installing matplotlib (3.1.0)
  - Installing pytest (3.10.1)

C:\Users\user1\Downloads\mpl>poetry run python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 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:\Users\user1\AppData\Local\pypoetry\Cache\virtualenvs\mpl-py3.7\lib\site-packages\matplotlib\__init__.py", line 200, in <module>
    _check_versions()
  File "C:\Users\user1\AppData\Local\pypoetry\Cache\virtualenvs\mpl-py3.7\lib\site-packages\matplotlib\__init__.py", line 194, in _check_versions
    module = importlib.import_module(modname)
  File "C:\Users\user1\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.
>>> import sys
>>> print(sys.path)
['', 'C:\\Users\\user1\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip', 'C:\\Users\\user1\\AppData\\Local\\Programs\\Python\\Python37\\DLLs', 'C:\\Users\\user1\\AppData\\Local\\Programs\\Python\\Python37\\lib', 'C:\\Users\\user1\\AppData\\Local\\Programs\\Python\\Python37', 'C:\\Users\\user1\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\mpl-py3.7', 'C:\\Users\\user1\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\mpl-py3.7\\lib\\site-packages']

Matplotlib version

  • Operating system: Win 10 x64
  • Matplotlib version: 3.1.0
  • Python version: 3.7.3

Installed via pip using poetry.

@cgohlke
Copy link
Contributor

cgohlke commented Jun 17, 2019

Should be fixed by #14316.

@Younes-L
Copy link

couldn't get 3.1.0 to work using pip install this morning on a fresh python 3.7.3 install , getting the same error. Had to downgrade to 3.0.0 and it worked

This merged PR looks newer than 3.1.0 , so right now both the error and the unhelpful error message persist

@AlexP11223
Copy link
Author

As I understand it's not really "fix", it just tells to install VC++ Redist (which version btw?) manually.

@cgohlke
Copy link
Contributor

cgohlke commented Jun 17, 2019

As I understand it's not really "fix", it just tells to install VC++ Redist

The final revision of #14316 loads the VC++ runtime DLL into the process before importing kiwisolver.

install VC++ Redist (which version btw?) manually

Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019

As a workaround until matplotlib 3.1.1 is released, you could pip install msvc-runtime

@dpsugasa
Copy link

I am still getting this problem with Python 3.6.9, Windows 10 x64, and matplotlib 3.1.1. I installed Microsoft Visual C++ Redistributable manually. I also tried pip install msvc-runtime. Downgrading matplotlib also doesn't work.

Still getting this error:

~\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\matplotlib_init_.py in _check_versions()
188 # Quickfix to ensure Microsoft Visual C++ redistributable
189 # DLLs are loaded before importing kiwisolver
--> 190 from . import ft2font
191
192 for modname, minver in [

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

@frank-yifei-wang
Copy link

Same issue on my machine (Win64, Conda 4.7.12, Python 3.7.3.final.0) - import matplotlib works fine but import matplotlib.pyplot as plt throws the error.

Spent hours trying different methods found from GitHub/StackOverflow with no luck. Finally fixed the issue by downgrading to matplotlib 3.0.3 ("older stable version" as stated by the official website).

conda uninstall matplotlib
conda install matplotlib==3.0.3

@nzmedic
Copy link

nzmedic commented Nov 16, 2019

Thanks @frank-wang-yifei , downgrade to 3.0.3 worked for me as well.

@Mridhula-M
Copy link

import matplotlib works fine but import matplotlib.pyplot as plt throws the error.

I'm getting the error for import matplotlib as well

conda uninstall matplotlib
conda install matplotlib==3.0.3

I tried uninstalling and reinstalling the older version but the error still remains

@frank-yifei-wang
Copy link

import matplotlib works fine but import matplotlib.pyplot as plt throws the error.

I'm getting the error for import matplotlib as well

conda uninstall matplotlib
conda install matplotlib==3.0.3

I tried uninstalling and reinstalling the older version but the error still remains

Try a "clean reinstallation"?

conda uninstall matplotlib
conda clean --all
conda install matplotlib==3.0.3

If still not working redo this but use pip install matplotlib==3.0.3 instead. Hope it works out for you.

@snoopy-coder
Copy link

In my case
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
I get the same error as you described:

import matplotlib works fine but import matplotlib.pyplot as plt throws the error.

matplotlib 3.0.3 is already installed, but the error still remains.

C:\Temp>pip list | find "matplotlib"
matplotlib         3.0.3

PS. I do not know how important this is, but newer versions 3.1.x fall on ft2font.cp37-win32.pyd and version 3.0.3 falls on _contour.cp37-win32.pyd

@tacaswell
Copy link
Member

@snoopy-coder Can you please create a topic in https://discourse.matplotlib.org/c/community/install/13 with:

  • your OS
  • your python version (and how you installed it)
  • matplotlib version (and how you installed it)
    • if you are compiling rather than getting a binary what compiler versions you are using
  • the full tracebacks you are getting

We do not use cython at all so there should be no pyd files involved in installing Matplotlib.

@HarlowBurgess
Copy link

Upgrading to matplotlib 3.2.1 fixed it for me.

OS: Windows 10 Pro 1909
Python: 3.7.4 64-bit (Microsoft Visual Studio 2019 Community - Python workload)
matplotlib: 3.2.1 (PyPI)

@tacaswell
Copy link
Member

I am going to close this as it is fixed in the current versions. If people land here and are still having trouble please create a new topic at https://discourse.matplotlib.org/c/community/install/13

@salimg517
Copy link

Same issue on my machine (Win64, Conda 4.7.12, Python 3.7.3.final.0) - import matplotlib works fine but import matplotlib.pyplot as plt throws the error.

Spent hours trying different methods found from GitHub/StackOverflow with no luck. Finally fixed the issue by downgrading to matplotlib 3.0.3 ("older stable version" as stated by the official website).

conda uninstall matplotlib
conda install matplotlib==3.0.3

worked THANX

@rameshvesalapu
Copy link

\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\matplotlib_init_.py in _check_versions()
188 # Quickfix to ensure Microsoft Visual C++ redistributable
189 # DLLs are loaded before importing kiwisolver
--> 190 from . import ft2font
191
192 for modname, minver in [

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

solution:Try to install the latest microsoft visual c++ redistributable file.
After installation was completed again the same problem arise the follow the below link
https://www.groovypost.com/howto/fix-visual-c-plus-plus-redistributable-windows-10/
Follow the steps Control panel---> programs and features --> go to the latest microsoft visual c++ redistribute file -->
right click on it and click on change and click on repair .
after restart your system .
In this way my problem was solved

@MarcelBeining
Copy link

Found that problem with matplotlib 3.3.1
Only solution was to pip install msvc-runtime

@StefanD986
Copy link

@tacaswell I can confirm that this issue is not solved and I can reliably reproduce the error:

Steps to reproduce

  1. Install Python 3.8 in a clean (=> no MSVC runtime installed) windows environment
    • I recommend running this in a Windows Sandbox. This avoids influence of MSVC runtime installed for other reasons, which might hide the bug otherwise.
  2. Install matplotlib: py -m pip install matlotlib
  3. Try and import matplotlib: py -c "import matplotlib"

Expected behaviour

Matplotlib should be successfully imported.

Alternatively: If the decision of matplotlib devs is to not let matplotlib depend on the msvc-runtime package (which might make sense as AFAIK the msvc-runtime package on PyPI is not an official Microsoft package), then at least a helpful error message should be presented.

Actual behaviour

ImportError is thrown and the error message does not provide any hint on how to resolve this issue:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
    _check_versions()
  File "C:\Users\WDAGUtilityAccount\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.

Notes

As others have mentioned the bug disappears when after pip install msvc-runtime. However I'm not sure whether this is an acceptable workaround, as it forces developers that use matplotlib to manage matplotlib's dependencies in their application's dependencies.

System info

Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32

@cgohlke
Copy link
Contributor

cgohlke commented Oct 30, 2020

I can confirm that this issue is not solved and I can reliably reproduce the error

The original issue was solved but the Windows wheels for matplotlib > 3.3.0 no longer include the required C++ runtime DLLs.

@zsx22705
Copy link

zsx22705 commented Nov 23, 2020

发现了matplotlib 3.3.1的问题,
唯一的解决办法是pip安装msvc-runtime

thank you

@bSharpCyclist
Copy link

I realize this is closed. I encounter the same issue when running a python file within VSCode. If then run the same file from a terminal in the same environment, then it runs just fine, no import error.

@benifhr
Copy link

benifhr commented Mar 26, 2021

Found that problem with matplotlib 3.3.1
Only solution was to pip install msvc-runtime

this fixed it for me, thanks!

@saumyagautam12
Copy link

Thanks it helped.

@dlangerm
Copy link

#14558 (comment)

Same issue on my end I'm afraid. pip install mscv-runtime fixed it but I had to restart VS code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests