Error loading DLL when importing cv2

I installed opencv on my windows machine using python 3.6 without any problems 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 saw this post

He says cv2 does not work with python 3 I was wondering if this is fixed or is there a way around it

+41
python opencv cv2
Apr 03 '17 at 12:37 on
source share
19 answers

You can download the latest version of OpenCV 3.2.0 for Python 3.6 on a 32-bit or 64-bit Windows machine, file search starts with opencv_python‑3.2.0‑cp36‑cp36m from this unofficial site . Then enter below command to install it:

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

I think it will be easier.

Update on 2017-09-15:

OpenCV 3.3.0 wheel files are now available on an unofficial site and are replaced by OpenCV 3.2.0 .

Update on 2018-02-15:

OpenCV 3.4.0 wheel files are now available on an unofficial site and are replaced by OpenCV 3.3.0 .

Update on 2018-06-19:

OpenCV 3.4.1 wheel files are now available on an unofficial site supporting CPython 3.5/3.6/3.7 and are replaced by OpenCV 3.4.0 .

Update on 2018-10-03:

OpenCV 3.4.3 wheel files are now available on an unofficial site supporting CPython 3.5/3.6/3.7 and are replaced by OpenCV 3.4.1 .

Update on 2019-01-30:

OpenCV 4.0.1 wheel files are now available on an unofficial site with support for CPython 3.5/3.6/3.7 .

Update on 2019-06-10:

OpenCV 3.4.6 and OpenCV 4.1.0 wheel files are now available on an unofficial site with support for CPython 3.5/3.6/3.7 .

+40
Apr 03 '17 at 16:50
source share

I took a long time to resolve this error! Launch command

 pip install opencv-contrib-python 
+34
Jan 24 '18 at 3:45
source share

If you are using Anaconda with python 3.5 , this is a problem in releasing Anaconda. (See This Question )

You can solve this problem by copying the python3.dll file to the Anaconda3 folder (where python.exe is located)

How to get "python3.dll"

  • In cmd enter python --version to find out if your installation is 64 bit or 32 bit
  • download Python 3.x embeddable zip file here
  • Extract the zip file and copy the python3.dll file to the Anaconda3 folder

But if you can upgrade to Anaconda with python 3.6 you will not run into this problem. If this is possible for you, then this is the recommended way ..

+33
May 29 '17 at 16:06
source share

Having spent too much time on this problem and having tried all the different answers, here is what I found:

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

  • This is really a bug in Anaconda 4.2 because they forgot to send python3.dll. They fixed this in future releases, but unfortunately 4.2 is the latest version with Python 3.5 by default. If you are stuck with Python 3.5 (for example, VS2015 knows only versions up to 3.5), you must manually download python3.dll, as described in @ Ramesh-X's answer.

  • If you can upgrade to Python 3.6 (which is currently difficult if you use OpenCV and VS2015), then just install the latest version of Anaconda and you won’t have to deal with any of them.

+8
Aug 29 '17 at 9:09 on
source share

I recently ran into a similar issue in Azure Windows Server 2012 r2 . I tried all the options with and without Anaconda, but none of them helped. After many conclusions, I found that mfplat.dll was missing , which is related to the Windows Media Service.

Therefore, you must manually install the functions so that you can get the DLLs associated with the window media service.

1. Turn Windows features on or off

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

3. Select "Desktop Experience" in the "User Interfaces and Infrastructure" section.

After that, all necessary dll media services for opencv will be available.

Therefore, if you plan to run your code in the cloud (Windows Server), please remember to select the Desktop Experience feature.

+7
Nov 06 '18 at 11:32
source share

There are many questions about this and many suggestions. None of them helped me in 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 has been resolved.

When I look in cv2.pyd with the dependency handler, 3.1 has no dependency on any missing dll. Opencv 3.4 has this missing dependency on this DLL:

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

maybe this is the problem.

PS: I have Win7 professional 64Bit, 32Bit Python 2.7.15

+6
Aug 29 '18 at 6:24
source share

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 tips helped (for example, installing OpenCV from an unofficial site or installing VC Redistributable).

I checked the DLL dependencies on ...\AppData\Local\conda\conda\envs\foo\Lib\site-packages\cv2\cv2.cp37-win_amd64.pyd using dumpbin.exe corresponding to this github problem . I noticed the MF.dll library, which, as I found out, belongs to the Windows Media Foundation.

Therefore, I installed the Media Feature Pack for N versions of Windows 10 and voila, the problem was resolved!

+3
Mar 26 '19 at 15:51
source share

I had the same problem when installing opencv 2.4.13 on Anaconda3 (Python 3.6) ... I was able to fix this problem by contacting Anaconda2 (Python 2.7)

+1
Jun 04 '17 at 21:20
source share

this is because the compiler or interpreter finds more than one package in the file, removes all the numbers of the same package that you have, and then leaves only one, and then tries to install. It serves

+1
Mar 29 '18 at 4:48
source share

The problem is related to the missing python3.dll file in Anaconda3.

To solve this problem, you just have to copy python3.dll to C:\Program Files\Anaconda3 (or where Anaconda3 is installed).

You can get python3.dll by downloading the binaries presented at the bottom of the Python release page and extracting python3.dll from a ZIP file.

+1
Apr 05 '18 at 21:31
source share

I had the same issue with python 3.6 (Anaconda3) and OpenCV 3.4.1 for spyder to work. Even after copying cv2.pyd to Anaconda3 Users / home / Anaconda3 / Lib / site-packages, this did not 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 to Anaconda3 Users / home / Anaconda3 / Lib / site-packages. They can be copied from the C: \ Users \ home \ Anaconda3 \ envs \ opencv \ Lib \ site-packages folder.

Finally Spyder started working

+1
Oct 05 '18 at 7:02
source share

I have the same problem. when I install WinPython programming and run opencv after copying the cv2.pyd file from the opencv directory, it will look like this: C: \ Users ..... \ Downloads \ opencv \ build \ python \ 2.7 \ x64, x64 or x86 Depends on your 32- or 64-bit devices. and insert into C: \ Users ..... \ Downloads \ WinPython-64bit-3.5.4.1Qt5 \ python-3.5.4.amd64 \ Lib \ site-packages, I prefer the previous python 3.5 over 3.6. Because when I "imported cv2" is installed (python 3.6), it shows directly: "ImportError: DLL loading error: the specified module was not found" Then I install python 3.5 and open the WinPyhton command line and click on "pip install opencv-python" .

The command line automatically loads opencv, it shows a process similar to this: "Opencv-python-3.3.0.10 has been successfully installed"

Finally, I try to run open cv like “import cv2”, it works I try to enter “cv2. Version ” and shows: “3.3.0”

0
Nov 29 '17 at 22:34
source share

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

0
Mar 22 '18 at 9:57
source share

(basic) 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 to get cv2 working, and I tried everything for two days.

0
Apr 04 '18 at 18:54
source share

If this helps someone, on the official Windows Python 3.6 docker image, to make this thing work, I had to copy the 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' 
0
Jan 31 '19 at 14:39
source share

Please remember, if you want to install the Python package / libraries for Windows,

You should always consider Python as unofficial binaries

Step 1:

Find your package, download the dependent version 2.7 or 3.6, which you can find in the Downloads / your_package_version.whl section called python wheel

Step 2:

Now install using pip,

 pip install ~/Downloads/your_packae_ver.whl 

this will install without any error.

0
Mar 11 '19 at 5:56
source share

I had the same problem and spent 3 full days fighting it. I tried everything that was offered: update pip, update Visual C ++, update Anaconda, manually upload files and almost all the solutions that I could find on the Internet. Here is what finally worked, maybe it will help someone else:

1- I refused the downloads based on Python 3 and Anaconda, as I noticed that they had several problems, and instead downloaded the bits of Python 2.7.16 6 4-.

2- Moved to where Pip was on my disk (for me, the path is C: \ Python27 \ Scripts), highlighting the path, selecting it, and typing "cmd", then enter so that the command line opens on this path (I noticed a skip of this usually leads to a couple of errors)

3- Updated Pip using python -m pip install --upgrade pip on CMD (again, skipping this and not updating, I did not skip this procedure)

4- I downloaded the corresponding Wheel file from https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv (after several attempts, the one that worked for me was opencv_python-2.4.13.7-cp27-cp27m-win_amd64. whl) I copied and pasted it into the same folder that Pip was in (C: \ Python27 \ Scripts for me), and then installed it via CMD using: pip install opencv_python-2.4.13.7-cp27-cp27m-win_amd64.whl . It always opens through CMD along this path, as shown in step 2

5- After step 4, when I imported OpenCV using import cv2 I no longer had a DLL error, but there was a numpy-related error (since I just installed this version of Python and therefore Numpy has not been installed yet). I installed numpy by typing pip install numpy and voila! The problem was resolved, and OpenCV was imported correctly.

Hope this helps someone.

0
Apr 03 '19 at 15:28
source share

Honestly, there are many good and complex answers here. I uninstalled my conda environment and installed it from scratch, trying to install opencv first. This fixed my problems. Therefore, if my environment was called fubar first make sure that all its instances are deactivated (including all IDEs that use it). Then remove this:

 conda remove --name fubar --all 

Now I just recreate my environment and add opencv first:

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

And then go from there. I always (always) install Spyder last, as this leads to errors when I do not.

0
Jul 22 '19 at 18:44
source share

Install Python using:

  • pip install opencv-python (latest version required)

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

To check cv2 version: import cv2 print (cv2 .__ version__)

-3
Jan 17 '18 at 10:49
source share



All Articles