14

Recently I start to get ImportError: DLL load failed: error when I import different libraries (for example scikit-learn or scipy and some others).

My assumptions is that I have broken something when I was trying to pip install opencv.

So, my question is how to resolve this problem that seems to be not library specific?

Can I pip install DLL or something like that? Can I just reinstall the whole Python? I am working on Windows. My version of Python is Python 2.7.10 :: Anaconda 2.3.0 (64-bit).

ADDED

If I print sys.path I get this:

['',
 'C:\\Anaconda\\Scripts',
 'C:\\Anaconda\\python27.zip',
 'C:\\Anaconda\\DLLs',
 'C:\\Anaconda\\lib',
 'C:\\Anaconda\\lib\\plat-win',
 'C:\\Anaconda\\lib\\lib-tk',
 'C:\\Anaconda',
 'C:\\Anaconda\\lib\\site-packages',
 'C:\\Anaconda\\lib\\site-packages\\Sphinx-1.3.1-py2.7.egg',
 'C:\\Anaconda\\lib\\site-packages\\cryptography-0.9.1-py2.7-win-amd64.egg',
 'C:\\Panda3D-1.9.2-x64',
 'C:\\Panda3D-1.9.2-x64\\bin',
 'C:\\Anaconda\\lib\\site-packages\\win32',
 'C:\\Anaconda\\lib\\site-packages\\win32\\lib',
 'C:\\Anaconda\\lib\\site-packages\\Pythonwin',
 'C:\\Anaconda\\lib\\site-packages\\setuptools-17.1.1-py2.7.egg',
 'C:\\Anaconda\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\myname\\.ipython']

What worries me is that there is a mixture of 32 and 64 versions. Another thing, maybe I just have different Pythons and I just need to call the proper one?

3
  • I'm not sure how to get you out of this problem, but if you start using virtualenv you'll limit the scope of such problems in the future..
    – thebjorn
    Dec 28, 2016 at 16:00
  • What's the whole error message?
    – gzc
    Dec 28, 2016 at 16:02
  • The whole error message is in German. It tells something like: ImportError: DLL load failed: the given module is not found.
    – Roman
    Dec 28, 2016 at 16:04

7 Answers 7

10

If anyone comes across this issue in Python > 3.8 with Windows, dll's are only loaded from trusted locations https://docs.python.org/3/whatsnew/3.8.html#ctypes This can be fixed by adding the dll path using os.add_dll_directory("PATH_TO_DLL")

2
  • 5
    Thanks @sam. This should be the correct answer! Some more detail for python beginners using Anaconda/Spyder on how to get this DLL path. 1) In console Anaconda CMD type echo %path% to see where your anaconda is installed. 2) In spyder's python console you can enter command import os, then run the os.add_dll_directory as sam suggests. Mine was: os.add_dll_directory("C://Users/MYNAME/Anaconda3/DLLs"). Windows users do not forget to change your slash direction from \ to / and first slash after : needs 2 //.
    – micstr
    Oct 13, 2021 at 8:59
  • 1
    For clarity - this will only work with Python 3.8 and newer. OP says it, but I read it differently than what was intended. I'm on Python 3.7. Python3.7: module 'os' has no attribute 'add_dll_directory'
    – PfunnyGuy
    Jul 19 at 18:54
4

I have managed to resolve the problem by reinstalling Python. First, I have uninstalled Python (like any other program in Windows). Then I have installed Anaconda distribution of Python. The problem is not present anymore.

2
  • 1
    I was getting the same error ( ImportError: DLL load failed ) on trying to pip or use jupyter notebook. Realized I had two versions of Python (including the one that comes with Anaconda). Uninstalling the other version of Python has solved the problem. Thanks!
    – Indi
    Dec 29, 2016 at 9:38
  • 1
    I really didn't want to do this but then after digging I found that I must have accidentally installed a 64-bit 2.7 update over a previous 32-bit 2.7 installation so I got this ImportError but only on rarely-used modules. Alas, reinstalling of course fixed it. Apr 2, 2019 at 15:30
2

I just encountered this exact problem and was struggling to solve it. I tried to reinstall anaconda, I reinstalled the relevant packages, I changed my environment - BUT NOTHING WORKED! eventually, after few hours, I managed to solve this problem with some few easy steps as described here :)

just type in the command line (one code-line at a time): conda install numpy then, conda install scipy then, pip install -U seaborn then, pip install -U numpy and finally, pip install -U scipy

That's it :) - it is now working! (it also fixed the error for all of the other libraries as well, such as sklearn, matplotlib etc.)

0

So I faced a similar issue; uninstalling and reinstalling Anaconda was the only way I found to fix it. To remove Anaconda and all its residual files I used the iobit uninstaller software, you can download it here:

https://www.iobit.com/en/recommend/iu.php

0

This is an old question, and sadly pops up in search results. The solution that actually works:

If re-installing python didn't work, you simply need to update pywin32

pip install pywin32==300

Read more here: ImportError: DLL load failed while importing shell

-1

I don't know but I opened the adminstrator cmd if don't know just hover over command promp and right click and you'll see the option of open in admistrator mode click over it just uninstall using pip uninstall package_name and don't close because the package_will be cached down and when you again command pip install package_name it should work ,just because it worked for me LOL if you close it you have to download it again like ffpyplayer is of 25 mbs so why to do that

-2

You can try to activate an enviroment. Activating environments is essential to making the software in the environments work well. Activation entails two primary functions: adding entries to PATH for the environment and running any activation scripts that the environment may contain. (Only work on conda 4.6 and later versions)

To activate, execute this first on cmd:

conda activate

The, run the jupyter notebook on cmd too

jupyter notebook

This work for me when I was trying to use "seaborn" and anothers packages like numpy, sklearn, and so on.

2
  • 1
    Please do not just post a link to a potential solution. An answer should always be able to answer the question even if the link is unable to be reached.
    – Thomas F
    Feb 28, 2021 at 4:26
  • I'm new around here, thanks for the suggestions Mar 4, 2021 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.