DLL load failed error when importing cv2
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
Solution 1:
I took a lot of time to solve this error! Run command
pip install opencv-contrib-python
Solution 2:
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.
Solution 3:
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
, typepython --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 toAnaconda3
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..
Solution 4:
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.
Solution 5:
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!