DLL load failed error when importing cv2
Asked Answered
D

28

85

I have installed opencv on my windows machine using python 3.6 without any issues, using:

pip install opencv-python

but when I try to import cv2 I get the following error

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

I have seen this post

It says cv2 doesn't work with python 3 I was wondering if this has been fixed or if there is a way around it

Durwin answered 3/4, 2017 at 12:37 Comment(7)
The latest supported version of python in OpenCV is 3.5 not 3.6Niemeyer
@kmario23: I tried with Python 3.5.0 and I still get the same error.Skippy
Check out the answer of @tientuyen07, it works for me. For python3.7.0 on Windows10.Keffer
Note cv2 definitely works with Python3 nobody should be using Python 2 any more! :)Tillandsia
I had it installed with conda. After uninstalling it and reinstalling using pip, it worked.Berneta
Installing for Anaconda you can refer to this answer which helped me.Adipose
Just run pip install opencv-python should work. I am using python38.Cyrenaica
D
58

You can download the latest OpenCV 3.2.0 for Python 3.6 on Windows 32-bit or 64-bit machine, look for file starts withopencv_python‑3.2.0‑cp36‑cp36m, from this unofficial site. Then type below command to install it:

  • pip install opencv_python‑3.2.0‑cp36‑cp36m‑win32.whl (32-bit version)
  • pip install opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl (64-bit version)

I think it would be easier.

Update on 2017-09-15:

OpenCV 3.3.0 wheel files are now available in the unofficial site and replaced OpenCV 3.2.0.

Update on 2018-02-15:

OpenCV 3.4.0 wheel files are now available in the unofficial site and replaced OpenCV 3.3.0.

Update on 2018-06-19:

OpenCV 3.4.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.0.

Update on 2018-10-03:

OpenCV 3.4.3 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.1.

Update on 2019-01-30:

OpenCV 4.0.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.

Update on 2019-06-10:

OpenCV 3.4.6 and OpenCV 4.1.0 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.

Update on 2023-02-11:

OpenCV 4.5.5 wheel files are now available in the unofficial site with CPython 3.7/3.8/3.9/3.10/3.11 support.

Dalpe answered 3/4, 2017 at 16:50 Comment(8)
AN UPDATE: opencv3.2.0 with opencv_contrib binaries for Python 3.5 and 3.6 are now available for download from the unoffice site. Look for entry consists of +contrib in the file name. For example, opencv_python‑3.2.0+contrib‑cp35‑cp35m‑win_amd64.whl.Dalpe
Requirement 'opencv_python-3.2.0-cp36-cp36m-win_amd64.whl' looks like a filename, but the file does not existAggrieved
It looks that opencv 3.2 for python 3.x are removed after my UPDATE. You may use opencv 3.3.Dalpe
A note for those who don't know, like I didn't: the cp in filenames there stands for CPython, so the number after that is your Python version.Skippy
Installed sucessfully, but got same error. File name opencv_python-4.5.3-cp310-cp310-win_amd64.whl, python 3.10.0, win11x64Behrens
I instralled successfully, but now have some error of "ImportError: numpy.core.multiarray failed to import", despite numpy actual version installed. Maybe it's some specific version needed, idk.Cooley
@Cooley See the update on 2023-02-11 above.Dalpe
will you please collapse all those "updates"? and prefix the entire post with a clear statement that you refer to builds by "Christoph Gohlke". "unofficial site" is meaningless. and while you're at it, please remove all mentions of outdated versions. I just had someone show up wondering why "3.2.0" is old. there is no reason to keep updating this post at all.Neither
W
91

I took a lot of time to solve this error! Run command

pip install opencv-contrib-python
Williamwilliams answered 24/1, 2018 at 3:45 Comment(6)
There are several issue about this question, but I find it's platform is not Windos10 + Python3.7.0. And your answer is works for me. Thanks a lot.Keffer
worked for me. I had installed opencv-python and some else, but this was the final thing.Uxorious
Works for win7 pyhton3.7.3 (Anaconda) - ThanksFruitless
Worked for me in a conda environment with python = 3.7.10Sabah
This works sometimes for meHalley
working with python 3.8 as of 2023. Installed camelot using `` conda install -c conda-forge camelot-py" and then used this solution.Cariole
D
58

You can download the latest OpenCV 3.2.0 for Python 3.6 on Windows 32-bit or 64-bit machine, look for file starts withopencv_python‑3.2.0‑cp36‑cp36m, from this unofficial site. Then type below command to install it:

  • pip install opencv_python‑3.2.0‑cp36‑cp36m‑win32.whl (32-bit version)
  • pip install opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl (64-bit version)

I think it would be easier.

Update on 2017-09-15:

OpenCV 3.3.0 wheel files are now available in the unofficial site and replaced OpenCV 3.2.0.

Update on 2018-02-15:

OpenCV 3.4.0 wheel files are now available in the unofficial site and replaced OpenCV 3.3.0.

Update on 2018-06-19:

OpenCV 3.4.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.0.

Update on 2018-10-03:

OpenCV 3.4.3 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.1.

Update on 2019-01-30:

OpenCV 4.0.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.

Update on 2019-06-10:

OpenCV 3.4.6 and OpenCV 4.1.0 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.

Update on 2023-02-11:

OpenCV 4.5.5 wheel files are now available in the unofficial site with CPython 3.7/3.8/3.9/3.10/3.11 support.

Dalpe answered 3/4, 2017 at 16:50 Comment(8)
AN UPDATE: opencv3.2.0 with opencv_contrib binaries for Python 3.5 and 3.6 are now available for download from the unoffice site. Look for entry consists of +contrib in the file name. For example, opencv_python‑3.2.0+contrib‑cp35‑cp35m‑win_amd64.whl.Dalpe
Requirement 'opencv_python-3.2.0-cp36-cp36m-win_amd64.whl' looks like a filename, but the file does not existAggrieved
It looks that opencv 3.2 for python 3.x are removed after my UPDATE. You may use opencv 3.3.Dalpe
A note for those who don't know, like I didn't: the cp in filenames there stands for CPython, so the number after that is your Python version.Skippy
Installed sucessfully, but got same error. File name opencv_python-4.5.3-cp310-cp310-win_amd64.whl, python 3.10.0, win11x64Behrens
I instralled successfully, but now have some error of "ImportError: numpy.core.multiarray failed to import", despite numpy actual version installed. Maybe it's some specific version needed, idk.Cooley
@Cooley See the update on 2023-02-11 above.Dalpe
will you please collapse all those "updates"? and prefix the entire post with a clear statement that you refer to builds by "Christoph Gohlke". "unofficial site" is meaningless. and while you're at it, please remove all mentions of outdated versions. I just had someone show up wondering why "3.2.0" is old. there is no reason to keep updating this post at all.Neither
W
38

If you are using Anaconda with python 3.5, this is a problem in the Anaconda release. (Refer this issue)

You can fix this issue by copying python3.dll file to Anaconda3 folder (where python.exe is located)

How to get "python3.dll"

  • In cmd, type python --version to find whether your installation is 64-bit or 32-bit
  • download python 3.x embeddable zip file from here
  • Extract the zip file and copy python3.dll file to Anaconda3 folder

But if you can move to Anaconda with python 3.6 you will not face this issue. If it is possible for you, then it is the recommended way..

Walton answered 29/5, 2017 at 16:6 Comment(1)
it works great... after spending 4 hrs, came to this post... helped me alot. currently using Anaconda3-4.1.1-Windows-x86_64 with Python 3.5.2 :: Continuum Analytics, Inc.Dehypnotize
P
28

Recently I have faced the similar issue in Azure Windows Server 2012 r2 . Tried all option with and without Anaconda but none of them helped. After lot of findings I found that mfplat.dll was missing which is related to Window Media Service.

Hence you have to manually install the features so that you can get dll related to window media service.

1.Turn windows features on or off

2.Skip the roles screen and directly go to Feature screen

3.Select "Desktop Experience" under "User Interfaces and Infrastructure"

After this all required dll of media services for opencv would be available.

So if you are planning to run your code in cloud(Window Server) then please dont forget to select Desktop Experience feature.

Phyto answered 6/11, 2018 at 11:32 Comment(5)
It worked for me on Windows Server 2012. Thanks a lotRonaronal
thanks for this answer! You saved me a lot of time and it worked perfectly on my Win2012R2!Filamentary
Running Windows Server 2012 R2 on AWS, and this fixed the problem.Underexpose
Thanks for this answer! perfectly worked in Win2012R2 edition.Pietra
Really thankful for this.Haskel
L
19

I ran into this problem on Windows 10 (N) with a new Anaconda installation based on Python 3.7 (OpenCV version 4.0). None of the above advice helped (such as installing OpenCV from the unofficial site nor installing VC Redistributable).

I checked DLL dependencies of ...\AppData\Local\conda\conda\envs\foo\Lib\site-packages\cv2\cv2.cp37-win_amd64.pyd using dumpbin.exe according to this github issue. I noticed a library MF.dll, which I figured out belongs to Windows Media Foundation.

So I installed Media Feature Pack for N versions of Windows 10 and voilà, the issue was resolved!

Legibility answered 26/3, 2019 at 15:51 Comment(3)
Thanks. Worked for me (Python 3.6 + OpenCv 3.4). I think the Media Feature Pack might be uninstalled during some major windows updateDeepfry
This was my issue and I don't use Anaconda. There's about 5 missing DLLs if the Media feature pack is not installed. You can go to Settings -> Apps -> Apps & Features then click on "Optional Features" and "+ Add a feature" to install the Media Feature Pack.Elyn
And also there is way to install via powershell dism, in my case lifesaver since recommended MS or KB methods did not workCatron
K
9

After spending too much time on this issue and trying out all different answers, here is what found:

  • The accepted answer by @thewaywewere is no longer applicable. I think this was applicable when opencv-python module still wasn't available.

  • This is indeed a bug in Anaconda 4.2 because they forgot to ship python3.dll. They have fixed this in next releases but unfortunately 4.2 is the last release with Python 3.5 as default. If you are stuck with Python 3.5 (for example VS2015 is only aware of versions up to 3.5) then you must manually download python3.dll as described in answer by @Ramesh-X.

  • If you can move on to Python 3.6 (which at present bit difficult if you are using OpenCV and VS2015) then just install latest Anaconda version and you don't have to deal with any of these.

Komatik answered 29/8, 2017 at 9:9 Comment(1)
Anaconda bug has been resolved. Best feedback I found on opencv and I wrote the troubleshooting of opencv-dll-load-failed afterwords.Stridulate
D
5

There are many questions on that and many suggestions. None of them helped me for the recent Opencv 3.4.16 and Python 3.6/3.7. Finally I switched to Pyhon 2.7.15 and installed opencv 3.1.0. The DLL-problem was solved.

When I look in cv2.pyd with dependency walker, the 3.1 has no dependency to one missing dll. Opencv 3.4 has this missing dependency to this dll:

API-MS-WIN-DOWNLEVEL-SHLWAPI-L1-1-0.DLL

may be this is the problem.

P.S.: I have Win7 pofessional 64Bit, 32Bit Python 2.7.15

Dollie answered 29/8, 2018 at 6:24 Comment(2)
None of the other answers helped but this one did. Rolling back opencv-python from 3.4 to 3.1.0.5 workedSirdar
Thanxx brother this is the best solution. Those who got the same error don't degrade the version just paste this dll file in system32 and systemWOW64Blether
T
4

Frankly there are a lot of very smart and complicated answers here. Mine is dumb and simple. I deleted my conda environment, re-installed from scratch, taking pains to install opencv first. This fixed my problems. Environments are meant to be temporary and diaphanous -- don't get too attached.

So if my environment was called fubar first make sure every instance is deactivated (including any IDEs that are using it). Then remove it:

conda remove --name fubar --all

Now I simply recreate my environment and add opencv first:

conda create --name fubar
conda activate fubar
conda install opencv

And then go from there. First open python and make sure import cv2 works. Then you should be on your way. Note I always (always) install Spyder last as it tends to screw things up when I don't.

Note, if that doesn't work, we have had some cases where people have to uninstall and reinstall Anaconda, and then things worked. Obviously a last resort.

Tillandsia answered 22/7, 2019 at 18:44 Comment(0)
W
4

In my case a major update of Windows 10 removed some Windows packages, so other methods (reinstalling opencv etc.) did not help. To fix it, install:

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

b) Media Feature Pack for N versions - needed only if you have Windows 10 N

Both need restart of PC.

Waitress answered 4/11, 2019 at 19:8 Comment(0)
M
2

this happens because the compiler or the interpreter is finding more than one package of the file, delete all the number of same package you have and then keep only one and then try to install. It serves

Mallon answered 29/3, 2018 at 4:48 Comment(0)
N
1

The issue is due to the missing python3.dll file in Anaconda3.

To fix the issue, you should simply copy the python3.dll to C:\Program Files\Anaconda3 (or wherever your Anaconda3 is installed).

You can get the python3.dll by downloading the binaries provided at the bottom of the Python's Release page and extracting the python3.dll from the ZIP file.

Nearsighted answered 5/4, 2018 at 21:31 Comment(0)
F
1

I had the same issue with python 3.6(Anaconda3) and OpenCV 3.4.1 for spyder to work. Even after copying cv2.pyd into Anaconda3 Users/home/Anaconda3/Lib/site-packages, it didn't work.

But found a solution

Later I installed OpenCV and Dlib on Anaconda and copied the generated cv2.cp36-win_amd64.pyd and dlib.cp36-win_amd64.pyd into Anaconda3 Users/home/Anaconda3/Lib/site-packages. These can be copied from environment folder C:\Users\home\Anaconda3\envs\opencv\Lib\site-packages.

Finally spyder started to work

Fishworm answered 5/10, 2018 at 7:2 Comment(0)
W
1

In my case, I had to install an older version of openCV (windows 10, Python 3.6.8)

pip install opencv-python==3.3.0.9
Writer answered 5/10, 2019 at 17:33 Comment(0)
M
1

This error can be caused by missing the following dll enter image description here

To have this dll install: https://www.microsoft.com/en-us/software-download/mediafeaturepack as already explained above

Mariomariology answered 26/9, 2020 at 13:37 Comment(0)
T
1

Running python 3.8.8 from windows 10 powershell from an anaconda 4.10.1 environment I installed opencv with

conda install opencv

I could import opencv no problem when I launched python from the command line.

However, when I tried to run code from inside pydev using the python interpreter for the specific anaconda environment I had activated, pydev couldn't find whichever dll it was looking for when importing opencv.

Setting the following environment variable resolved the issue:

CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1

Source: PyDev/Eclipse not loading _mklinit when run from a Conda environment

Which points to this trouble shooting description for a different library loading issue: https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#numpy-mkl-library-load-failed

Tongue answered 12/7, 2021 at 14:57 Comment(0)
E
1

I had the same problem, it seems openCV requires Windows Media Feature pack which is not installed on Windows 10 N by default, please install it using the following link:

https://www.microsoft.com/en-us/software-download/mediafeaturepack

Enthalpy answered 23/6, 2022 at 16:19 Comment(0)
W
1

I managed to get it to work by installing python 3.9.12 in a new environment (using conda), and then installing opencv in that environment. Because of my python version, opencv version 4.5.5 was installed instead of version 4.60.

(I had already updated VC2015-2022 and added the python3.dll to PATH; neither of these worked.)

Wesle answered 16/8, 2022 at 10:39 Comment(0)
T
0

I had the same issue when installing opencv 2.4.13 on Anaconda3 (Python 3.6)... I managed to fix this issue by reverting to Anaconda2 (Python 2.7)

Trinetta answered 4/6, 2017 at 21:20 Comment(1)
cv2 doesn't mean OpenCV 2.x.x. To use OpenCV 3.x.x, has to import cv2. OpenCV2.x.x is relatively old, seems no one compiled it for Python 3.x and upload to Anaconda Repository. Refer to this post on the file page to find out the OpenCV and supported Python version.Dalpe
A
0

I have the same problem. when I install WinPython programming, and run opencv after copy the cv2.pyd file from my opencv directory, it will be like this: C:\Users.....\Downloads\opencv\build\python\2.7\x64, x64 or x86 is depend on your 32 or 64 bit devices. and paste to C:\Users.....\Downloads\WinPython-64bit-3.5.4.1Qt5\python-3.5.4.amd64\Lib\site-packages, I prefer the previous python 3.5 than 3.6. Because when I "import cv2" installed (python 3.6) it shows directly: "ImportError: DLL load failed: The specified module could not be found" Then I install python 3.5 and open WinPyhton Command prompt and type "pip install opencv-python".

The command prompt download opencv automatically, it shows the process like this "Successfully installed opencv-python-3.3.0.10"

Finally, I try to run open cv by type "import cv2", it works i try to type "cv2.version", and shows: '3.3.0'

Alvaroalveolar answered 29/11, 2017 at 22:34 Comment(1)
I think the right answer is open cv isn't supported in py-3.6. (based on comment on the question). Also, there is lot of formatting options out here.. for example, you could say import cv2 instead of "import cv2". just use ` for quotes.. welcome to SO.Daric
P
0

Under Winpython : the Winpython-64bit-.../python_.../DLLs directory the file cv2.pyd should be renamed to _cv2.pyd

Postfix answered 22/3, 2018 at 9:57 Comment(0)
N
0

(base) C:\WINDOWS\system32>conda install C:\Users\Todd\Downloads\opencv3-3.1.0-py35_0.tar.bz2

I ran this command from anaconda terminal after I downloaded the version from https://anaconda.org/menpo/opencv3/files

This is the only way I could get cv2 to work and I tried everything for two days.

Nicknack answered 4/4, 2018 at 18:54 Comment(0)
S
0

If this helps someone, on official python 3.6 windows docker image, to make this thing work I had to copy following libraries from my desktop:

C:\windows\system32

aepic.dll
avicap32.dll
avifil32.dll
avrt.dll
Chakra.dll
CompPkgSup.dll
CoreUIComponents.dll
cryptngc.dll
dcomp.dll
devmgr.dll
dmenterprisediagnostics.dll
dsreg.dll
edgeIso.dll
edpauditapi.dll
edputil.dll
efsadu.dll
efswrt.dll
ELSCore.dll
evr.dll
ieframe.dll
ksuser.dll
mf.dll
mfasfsrcsnk.dll
mfcore.dll
mfnetcore.dll
mfnetsrc.dll
mfplat.dll
mfreadwrite.dll
mftranscode.dll
msacm32.dll
msacm32.drv
msvfw32.dll
ngcrecovery.dll
oledlg.dll
policymanager.dll
RTWorkQ.dll
shdocvw.dll
webauthn.dll
WpAXHolder.dll
wuceffects.dll

C:\windows\SysWOW64

aepic.dll
avicap32.dll
avifil32.dll
avrt.dll
Chakra.dll
CompPkgSup.dll
CoreUIComponents.dll
cryptngc.dll
dcomp.dll
devmgr.dll
dsreg.dll
edgeIso.dll
edpauditapi.dll
edputil.dll
efsadu.dll
efswrt.dll
ELSCore.dll
evr.dll
ieframe.dll
ksuser.dll
mfasfsrcsnk.dll
mfcore.dll
mfnetcore.dll
mfnetsrc.dll
mfplat.dll
mfreadwrite.dll
mftranscode.dll
msacm32.dll
msvfw32.dll
oledlg.dll
policymanager.dll
RTWorkQ.dll
shdocvw.dll
webauthn.dll
wuceffects.dll`
Slurp answered 31/1, 2019 at 14:39 Comment(0)
A
0

Please Remember if you want to install python package/libraries for windows,

you should always consider Python unofficial Binaries

Step 1:

Search for your package, download dependent version 2.7 or 3.6 you can find it under Downloads/your_package_version.whl its called python wheel

Step 2:

Now install using pip,

pip install ~/Downloads/your_packae_ver.whl

this will install without any error.

Aney answered 11/3, 2019 at 5:56 Comment(0)
A
0

I had the same problem and spent 3 full days wrestling with it. I tried everything suggested: upgrading pip, updating Visual C++, updating Anaconda, manually downloading files and basically every solution I could find on the web. Here's what finally worked maybe it'll help someone else:

1- I ditched Python 3 and Anaconda-based downloads since I noticed they had several problems and downloaded Python 2.7.16 64-bits instead.

2- Navigated to where Pip was located on my drive (for me the path is C:\Python27\Scripts) highlighted the path by selecting it, and typed "cmd" then enter so the Command Prompt opens on that path (I noticed skipping this usually brings about a couple errors)

3- Updated Pip using python -m pip install --upgrade pip on the CMD (again, skipping this and not updating it didn't let this procedure go through)

4- Downloaded the appropriate Wheel file from https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv (after trying several the one that worked for me was opencv_python-2.4.13.7-cp27-cp27m-win_amd64.whl) I copy-pasted it to the same folder Pip was in (C:\Python27\Scripts for me) and then installed it through CMD using: pip install opencv_python-2.4.13.7-cp27-cp27m-win_amd64.whl. Always through CMD opened on that path as showed in step 2

5- After step 4 when I imported OpenCV using import cv2 I didn't have the DLL error anymore but an error related to numpy (since I had just installed that version of Python and so Numpy wasn't installed yet). I installed numpy by typing pip install numpy and voilà ! The problem was solved and OpenCV imported correctly.

Hope this helps someone.

Anamorphoscope answered 3/4, 2019 at 15:28 Comment(0)
I
0

If you are using a server or docker enviroment without a gui (e.g. Windows Core Server) make sure that you use the headless version of cv2:

pip install opencv-contrib-python-headless
Infundibuliform answered 16/5, 2022 at 15:23 Comment(0)
T
0

Windows 11 N

This a final fix for the people who don't use anaconda.

simply there are missing DLL files, that's it

download the latest version of

https://sourceforge.net/projects/opencvlibrary/

Then after you extract it search for .dll files and copy all of them and paste into C:\Windows\System32 and approve for replacing.

That's it !

Teddy answered 17/10, 2022 at 20:41 Comment(0)
R
0

On Windows 10 with virtual environment based python (3.11.4) scripts I managed to have OpenCV 4.8.1.78 installed with the following command -

pip install opencv-python

Please note that for some reason this installed win_amd64 version. So far it has worked well!!

Retarder answered 23/10, 2023 at 19:16 Comment(0)
I
-4

Install python using:

  • pip install opencv-python(It will take the latest version)

Make sure opencv-python is installed in path(\Python\Python36\Lib\site-packages), you will find cv2 folder over there.

To check the version of cv2: import cv2 print(cv2.__version__)

Indulge answered 17/1, 2018 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.