17

I use the Anaconda Python distribution: Python 2.7 x64 with Windows 7 SP1 x64 Ultimate.

When I do import matplotlib.pyplot I get ImportError: DLL load failed: The specified module could not be found.. What could be the issue?

Full error stack:

Traceback (most recent call last):
  File "C:\svn\hw4\code\test_con.py", line 1, in <module>
    import matplotlib.pyplot 
  File "C:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 27, in <module>
    import matplotlib.colorbar
  File "C:\Anaconda\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
    import matplotlib.collections as collections
  File "C:\Anaconda\lib\site-packages\matplotlib\collections.py", line 27, in <module>
    import matplotlib.backend_bases as backend_bases
  File "C:\Anaconda\lib\site-packages\matplotlib\backend_bases.py", line 56, in <module>
    import matplotlib.textpath as textpath
  File "C:\Anaconda\lib\site-packages\matplotlib\textpath.py", line 22, in <module>
    from matplotlib.mathtext import MathTextParser
  File "C:\Anaconda\lib\site-packages\matplotlib\mathtext.py", line 63, in <module>
    import matplotlib._png as _png
ImportError: DLL load failed: The specified module could not be found.

conda update -f numpy, conda update -f libpng, and conda update -f matplotlib did not help.

Output of conda list matplotlib:

C:\Anaconda>conda list matplotlib
# packages in environment at C:\Anaconda:
#
matplotlib                1.4.3               np110py27_2
matplotlib-venn           0.11                      <pip>

The issue appeared after running conda update --all.

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
  • The use here seems to have encountered the same problem and solved it - http://stackoverflow.com/questions/20201868/importerror-dll-load-failed-the-specified-module-could-not-be-found. Also, small world :) – Rohit Pandey Nov 01 '15 at 06:00
  • what is the output of `conda list matplotlib`? – cel Nov 01 '15 at 07:07
  • @cel Thanks, sorry I had forgotten to mention the matplotlib version, I've added it at the end of the question! – Franck Dernoncourt Nov 01 '15 at 18:03
  • @RohitPandey Thanks, I've checked it and I do have `msvcp71.dll` and `msvcr71.dll` in both `C:\Windows\System32` and `C:\Windows\SysWOW64`. It looks like in the other question they don't use Anaconda Python, maybe that changes the solution, no idea... Small world indeed :) – Franck Dernoncourt Nov 01 '15 at 18:08

11 Answers11

15

I fixed this on my Windows machine by adding [Anaconda]/Library/bin to my PATH.

Dr. Pain
  • 689
  • 1
  • 7
  • 16
  • 1
    This worked for me. PyQt4 has the same issue. As far as I understand the build scripts for Anaconda are changing... Might cause issues for a little. See here:https://github.com/spyder-ide/spyder/issues/2765#issuecomment-152216201 – Onlyjus Nov 05 '15 at 18:16
  • @Onlyjus I first had the issue with PyQt4 indeed. `conda update -f matplotlib` solved it but then I had [other errors](http://stackoverflow.com/a/33510674/395857)... – Franck Dernoncourt Nov 06 '15 at 20:15
8

I have had this problem as well. It seems to have cropped up in the last week or two. It seems like something in the scipy stack was compiled incorrectly. In the near term:

conda install anaconda

will roll your system back to a stable anaconda distribtution.

7

I fixed this by installing libpng:

conda install libpng
Vasco
  • 1,177
  • 11
  • 28
6

I suppose the related issue is here: https://github.com/conda/conda/issues/1753

I solved the same problem by re-installing Anaconda.

Dalar
  • 135
  • 1
  • 7
  • 1
    Direct link to summary with fixing instructions: https://github.com/conda/conda/issues/1753#issuecomment-154885530 – bastelflp Nov 12 '15 at 09:34
2

The SciPy stack which came by default with Anaconda was corrupted in my case.

conda and pip are two different package managers which you can use to install python packages. conda can install various packages, it installs python itself as a package. pip caters to python users.

The conda packages were corrupted, so removing that package, which came by default, and installing it again using pip worked for me.

Try the following:

1. Create a new environment

This step is performed only as a safety measure. You can skip this step.

Open Anaconda prompt and

conda create --name testtrial python=3  //install whichever version of Python you want 
activate testtrial

2. Removing and installing new packages

conda remove matplotlib //required only if you skipped the first step and are working in the default(root) environment 
pip install matplotlib

That should solve the problem.


A quick guide on working with conda.

Vivek Teega
  • 21
  • 2
  • 2
1

Ensure you have closed all python stuff when you run this. Using the following code at the command prompt (not ipython prompt) produces an environment named "working" with Anaconda 2.2.0, Cython 0.22, Numpy 1.9.2 py33_0, Pandas 0.15.2, and Python 3.3.5.

conda create -n working python=3 anaconda

To then use the environment run

activate working

Now you can launch ipython or notebook and (at a minimum) matplotlib should import.

0

I met the same error prompt. At last I found that I open the jupyter notebook in a different enviroment, not the enviroment that I used before. It means the module is not in your directory of your jupter noetbook enviroment. So I just open jupyter notebook in the original enviroment, the problem solved.

Yong Yang
  • 126
  • 6
0

Try downgrading to a lower version, this command worked for me:

conda install libpng=1.6.22

This downgrades matplotlib and some other packages too, but seems to play well together.

Olaf
  • 158
  • 7
0

Earlier I was also facing the same issue which is resolved by downloading the latest supported Visual C++ downloads redistributable files.

Link: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

0

I just uninstalled my current numpy and installed a wheel numpy from this link.

This has solved my issue. I guess we shoudn't use dll from random source.

Srikanth Reddy
  • 121
  • 1
  • 10
0

If you installed matplotlib with pip, Add environment location to windows PATH

Erfan
  • 11
  • 4