76

I have installed Python 2.5.4, Numpy 1.5.0 win32, Matplotlib 1.0.0 win32, pywin32 218. Still not able to plot graphs in Python. Here is the error I am getting :

      import pylab
   File "C:\Python25\lib\site-packages\pylab.py", line 1, in <module>
      from matplotlib.pylab import *
   File "C:\Python25\lib\site-packages\matplotlib\pylab.py", line 216, in <module>
      from matplotlib import mpl  # pulls in most modules
   File "C:\Python25\lib\site-packages\matplotlib\mpl.py", line 1, in <module>
      from matplotlib import artist
   File "C:\Python25\lib\site-packages\matplotlib\artist.py", line 6, in <module>
      from transforms import Bbox, IdentityTransform, TransformedBbox, TransformedPath
   File "C:\Python25\lib\site-packages\matplotlib\transforms.py", line 34, in <module>
      from matplotlib._path import affine_transform
ImportError: DLL load failed: The specified module could not be found.

Please kindly help..

DesaiM
  • 1,385
  • 2
  • 10
  • 14
  • How did you install it? This looks like some of the c-extensions are not properly compiled/installed. – tacaswell Nov 25 '13 at 21:46
  • For scientific python on windows, your best bet is to install WinPython, Python(x,y), Enthought Python or Anaconda rather than trying to install everything manually. Any of these will install most packages you are likely to need, and should configure them correctly. – DaveP Nov 26 '13 at 08:41
  • 4
    Loading `...\site-packages\matplotlib\_path.pyd` with Dependency Walker might give you some clues on which DLL its about. If its all compiled properly it might also be a PATH issue, perhaps another version of the DLL is picked up because it comes 'first' in the PATH variable. This site has good precompiled binaries for Windows: http://www.lfd.uci.edu/~gohlke/pythonlibs/ – Rutger Kassies Nov 26 '13 at 08:59
  • Thank you all for answering my query, but the actual problem was different and I found its solution. – DesaiM Nov 27 '13 at 00:02
  • https://stackoverflow.com/questions/44537131/numpy-library-importerror-dll-load-failed-the-specified-procedure-could-not-be – Shivendra Agarwal Dec 30 '22 at 10:49

11 Answers11

26

I had the same issue with importing matplotlib.pylab with Python 3.5.1 on Win 64. Installing the Visual C++ Redistributable für Visual Studio 2015 from this links: https://www.microsoft.com/en-us/download/details.aspx?id=48145 fixed the missing DLLs.

I find it better and easier than downloading and pasting DLLs.

ubiquibacon
  • 10,451
  • 28
  • 109
  • 179
Fabian Polles
  • 361
  • 3
  • 3
  • Had a similar problem with spacy on Windows 7, Python 3.7.6 from python.org. The stacktrace was File "C:\Users\user_profile\Desktop\new_pro\venv\lib\site-packages\spacy\pipeline\__init__.py", line 4, in from .pipes import Tagger, DependencyParser, EntityRecognizer, EntityLinker File "pipes.pyx", line 1, in init spacy.pipeline.pipes ImportError: DLL load failed: The specified module could not be found. With the link above it finally worked. You saved my day! – Pegolon Feb 13 '20 at 14:20
25

(I found this answer from a video: http://www.youtube.com/watch?v=xmvRF7koJ5E)

  1. Download msvcp71.dll and msvcr71.dll from the web.

  2. Save them to your C:\Windows\System32 folder.

  3. Save them to your C:\Windows\SysWOW64 folder as well (if you have a 64-bit operating system).

Now try running your code file in Python and it will load the graph in couple of seconds.

Michael Currie
  • 13,721
  • 9
  • 42
  • 58
DesaiM
  • 1,385
  • 2
  • 10
  • 14
  • Saved my day! But why is it picking up from proper paths? – everlasto Nov 10 '14 at 09:52
  • 3
    If that's is not the way, request @JFFIGK to please suggest the solution. – Sivaram Boina Feb 14 '19 at 04:18
  • 2
    Pefhaps it is simpler than this? When I had the same error in another context, I followed https://stackoverflow.com/questions/44537131/numpy-library-importerror-dll-load-failed-the-specified-procedure-could-not-be and there the answer of @User1024, adding a Path variable. – questionto42 May 20 '20 at 19:50
  • 13
    Please don't trust dlls found on some YouTube video - this is a really dangerous solution. Install the needed dlls from official Microsoft sources if possible. – unddoch Apr 02 '21 at 11:56
  • Hi. I tried this, however, it doesn't solve my problem. Not sure why. – hbstha123 Apr 27 '21 at 19:03
  • I'm getting the same error for the news3k package myself now, just out of the blue after having used it for months and not made any apparent change (but I get a different backtrace). How did you know that it was `msvcp71.dll`and `msvcr71.dll` that was missing? – HelloGoodbye Feb 24 '23 at 12:01
23

For Windows 10 x64 and Python:

Open a Visual Studio x64 command prompt, and use dumpbin:

dumpbin /dependents [Python Module DLL or PYD file]

If you do not have Visual Studio installed, it is possible to download dumpbin elsewhere, or use another utility such as Dependency Walker.

Note that all other answers (to date) are simply random stabs in the dark, whereas this method is closer to a sniper rifle with night vision.

Case study 1

  1. I switched on Address Sanitizer for a Python module that I wrote using C++ using MSVC and CMake.

  2. It was giving this error: ImportError: DLL load failed: The specified module could not be found

  3. Opened a Visual Studio x64 command prompt.

  4. Under Windows, a .pyd file is a .dll file in disguise, so we want to run dumpbin on this file.

  5. cd MyLibrary\build\lib.win-amd64-3.7\Debug

  6. dumpbin /dependents MyLibrary.cp37-win_amd64.pyd which prints this:

    Microsoft (R) COFF/PE Dumper Version 14.27.29112.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    Dump of file MyLibrary.cp37-win_amd64.pyd
    
    File Type: DLL
    
      Image has the following dependencies:
    
        clang_rt.asan_dbg_dynamic-x86_64.dll
        gtestd.dll
        tbb_debug.dll
        python37.dll
        KERNEL32.dll
        MSVCP140D.dll
        VCOMP140D.DLL
        VCRUNTIME140D.dll
        VCRUNTIME140_1D.dll
        ucrtbased.dll
    
      Summary
    
         1000 .00cfg
        D6000 .data
         7000 .idata
        46000 .pdata
       341000 .rdata
        23000 .reloc
         1000 .rsrc
       856000 .text
    
  7. Searched for clang_rt.asan_dbg_dynamic-x86_64.dll, copied it into the same directory, problem solved.

  8. Alternatively, could update the environment variable PATH to point to the directory with the missing .dll.

Please feel free to add your own case studies here! I've made it a community wiki answer.

Contango
  • 76,540
  • 58
  • 260
  • 305
  • it looks like "readelf -d". Is any way to see information about possible load status from "dumpbin"? Something like "ldd" – shs_sf Jan 24 '21 at 19:58
  • 2
    This helped me fixed but I had to check the dependencies of my dlls to (I used Qtcore which needed libstdc++, libwinpthread and libgcc).Not having those dll in the folder caused the import error. – f222 Feb 02 '21 at 13:10
  • @f222 Yes, this would work just as well. Dumpbin is just one method to check the DLL dependencies, there are others. – Contango Feb 04 '21 at 15:45
  • 3
    This answer deserves more upvotes. It gives an insight about any `ImportError` problem where this is the top resulting page. – Burak Mar 08 '21 at 14:55
7

Since Python 3.8, it is possible that Dependencies or dumpbin /dependents reports no dependency issue, but one still gets the error "The specified module could not be found". This is because the PATH variable is no longer used for resolving DLLs of binary modules!

The solution is to use os.add_dll_directory:

import os
os.add_dll_directory(r"C:\path\to\your\dll\directory")
import your_module
Lithy
  • 817
  • 12
  • 23
5

Installing the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 worked for me with a similar problem, and helped with another (slightly different) driver issue.

4Oh4
  • 2,031
  • 1
  • 18
  • 33
2

Quick note: Check if you have other Python versions, if you have removed them, make sure you did that right. If you have Miniconda on your system then Python will not be removed easily.

What worked for me: removed other Python versions and the Miniconda, reinstalled Python and the matplotlib library and everything worked great.

Dash_bi
  • 21
  • 2
2

I installed vc++ which solved this problem.

Yogesh Jog
  • 707
  • 6
  • 8
1

Reinstall the related packages.

I have the same issue with numpy. I first uninstalled it:

pip uninstall numpy

and then installed again

pip install numpy==1.20.1

I needed that specific version. If you want to install other numpy versions, you may ignore ==1.20.1.

Also, during the installation, I received errors such as

statsmodels 0.12.2 requires patsy>=0.5, which is not installed.

I installed those missing prerequisites as well. e.g.,

pip install patsy
Hadij
  • 3,661
  • 5
  • 26
  • 48
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

This might be issue of missing Microsoft Visual C++ Redistributable packages for Visual Studio 2015, 2017, 2019, and 2022 in your machine. Use the following link to download the distributable and install it in your machine.

VC_redist.x64.exe

For more: Microsoft Visual C++ Redistributable Latest Supported Downloads

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0

I've been through this error and what I found after a lot of investigation:-

issue was in Opencv==4.5.1 build from source with cuda and flag cuda_with_fast_math=on

I just rebuild OpenCV and disable

cuda_with_fast_math

make sure that the shared library builded with cv version matched your current version

and it works for me.

Baher El Naggar
  • 181
  • 1
  • 5