Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot import matplotlib with Python 3.7.x on Win10Pro #14322

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

Closed
ullix opened this issue May 25, 2019 · 7 comments
Closed

Cannot import matplotlib with Python 3.7.x on Win10Pro #14322

ullix opened this issue May 25, 2019 · 7 comments
Milestone

Comments

@ullix
Copy link

ullix commented May 25, 2019

Bug report

Bug summary

Attempting to IMPORT matplotlib under Python 3.7.x on a Win10Pro results in error: "ImportError: DLL load failed: The specific module could not be found".
DLL name not given.
However, first importing PyQt5, and only then importing matplotlib works as it should.

Code for reproduction

  • install Python 3.7.x (tested both 3.7.2 and 3.7.3) on Win10Pro
  • install matplotlib (version 3.1.0) with pip - installs fine, no issues
  • install PyQt5 (version 5.12.2) with pip - installs fine, no issues
  • start Python
  • under Python, enter command: "import matplotlib"
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:\Program Files\Python37\lib\site-packages\matplotlib\__init__.py", line 200, in <module>
    _check_versions()
  File "C:\Program Files\Python37\lib\site-packages\matplotlib\__init__.py", line 194, in _check_versions
    module = importlib.import_module(modname)
  File "C:\Program Files\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.
>>>
>>>
# importing matplotlib works fine when PyQt5 imported first
>>> import PyQt5
>>> import matplotlib
>>> import serial
>>>
>>> ^Z

Actual outcome

# see above

Expected outcome

using matplotlib should not depend on importing PyQt5 first; but when done, code works fine

Matplotlib version

  • Operating system: Win10Pro
  • Matplotlib version: 3.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg right after importing; in the full code using qt5agg
  • Python version: 3.7.2, 3.7.3, 64 bit
  • Jupyter version (if applicable): n.a.
  • Other libraries:

Python installed from Win installer
matplotlib and PyQt5 installed with pip

@jklymak
Copy link
Member

jklymak commented May 25, 2019

I think this is a duplicate. #14303

@ullix
Copy link
Author

ullix commented May 25, 2019

The offered solution to install 'Microsoft Visual C++ 2015 redistributable' is not helping me. I don't own it, and don't plan to buy it, as I am usually on Linux only.

If it is a kiwisolver issue, what should it provide that now comes from PyQt5? I notice that there is no folder kiwisolver, which is where I suppose any DLL file contributed by kiwis should reside?

@jklymak
Copy link
Member

jklymak commented May 25, 2019

I don't understand the pyqt5 interaction. My guess is that you don't have Tk installed properly and the import fails when it tries to import Tk. Check your matplotlibrc and either clear the backend default or set it to Qt5Agg; its probably set to tk.

@jonascj
Copy link

jonascj commented May 25, 2019

Also, are you on Windows now or Linux, you mention both? Microsoft Visual C++ redist are free as far as I know: https://www.microsoft.com/en-us/download/details.aspx?id=48145

It is likely only a requirement on Windows, not linux. I've never encountered this on Linux.

@tacaswell tacaswell added this to the v3.1.1 milestone May 26, 2019
@tacaswell
Copy link
Member

See the discussion at the end of #14316

In very short summary:

  • for c++ code on windows you need the "Microsoft Visual C++ 2015 redistributable" which is (as I understand it the c++ standard library)
  • kiwisolver, pyqt, (and Matplotlib!) all depend on this library
  • pyqt and matplotlib include them in the wheels, kiwisolver does not
  • in 3.1 matplotlib put an import of kiwisolver before we import any of our c++ extensions, hence this failure now, but not on previous versions of mpl

I am going to close this in favor of #14303 (which I just marked as release critical for 3.1.1).

Thank you for reporting this @ullix !

@ullix
Copy link
Author

ullix commented May 26, 2019

Indeed, the regression came with matplotlib 3.1.0. When forcing installation of predecessor matplotlib 3.0.3 all works fine.

@nkligang
Copy link

Indeed, the regression came with matplotlib 3.1.0. When forcing installation of predecessor matplotlib 3.0.3 all works fine.

This works for me too. very strange problem, it took me a lot of time.

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

No branches or pull requests

5 participants