"DLL load failed" when import cv2 (opencv)
Asked Answered
L

20

24

In [windows server 2012 R2 x64, python 3.7 64x]

pip install opencv-contrib-python

installed without any error .
and when I try to import it

import cv2

show me this error :

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import cv2
  File "C:\Program Files\Python37\lib\site-packages\cv2\__init__.py", line 3, in
 <module>
    from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.

and I see another topic about this error but their solution does not work for me :
- DLL load failed error when importing cv2
- Failure to import cv2 in python : DLL load failed
- and a lot of pages in here

some of them say about that problem because anaconda, and I don't have anaconda even. and many say that problem 32 or 64 version, I try both and disappointment. many about system variables...
what dll failed to load? cv2? why?

what i try till now:

  • change python version : 3.5, 3.7, 2.7 in 86x and 64x (uninstall complete last version and delete all remain files in program files ... then install new one)

  • try with another packages like : opencv-python, opencv-contrib, try install specific versions with .whl (in some topic i read about this so install numpy-1.14.5+mkl-cp37-cp37m-win_amd64.whl and opencv_python-3.4.3+contrib-cp37-cp37m-win_amd64.whl but anything not change)

  • import numpy before cv2 for every test

  • installed Microsoft Visual C++ 2015 Redistributable Update 3 , 2008 , 2010 , 2017 for 64x

UPDATE
NEXT 2 DAY

I try to manage missing dll base on dependency walker that mention in bellow post, download all dll and put them in system 32, its a good clue but not solve the problem.

DAY 4,5

my next step , trying compile OpenCV in my machine , install visual studio 2012 + cmake and base on document compile 2 version , 64x and 32 , compiling have a lot of problem itself (like missing some lib from c lang and need to install Visual C++ Redistributable for Visual Studio 2012 ...) and I resolve all of them ,then I have 2 success compiled version but both have the same problem with missing dll, the compile process is so slow and give 2 day from me. so if fail on this mission :/ I search for a new way...

DAY 6

my next step is to try to run OpenCV in my machine with docker ( I try but docker windows just install on windows 10 and windows server 2016) so I search for an alternative. I found Vagrant that work like docker but with VM (visual box) today my time spend for this articles, it's amazing, the concept of docker and vagrant is so Attractive, and I play with this like that I have new puzzle :) first error show on ... and limitless errors go on :

Day 7

Vagrant tests failed too because my windows server 2012 is a vb machine (visual server) and run a visual box in another visual box impossible! so I need new clues :

Day 8-9

try install vagrant with VMware , I download VMware, unfortunately this plugin is not free (79$) so I try to work with pythonanywhere.com that 'gives you access to machines with a full Python environment already installed.' in this free account, you can't openurl with urllib , and more limit... so I wanna try to install ubuntu in VMware my self... I read here results after work. it's Impossible with same reason vb (visual box)

Lentil answered 15/9, 2018 at 23:20 Comment(2)
See this questionRosarosabel
Can you try to add the .dll file to the same folder as the .pyd file? Maybe the remote server isn't checking in system32.dll?Respectability
A
36

This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.

The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack

Be careful to choose the version that works with your current version of windows.

If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9

Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.

Update May 2020: There is a new way to install media pack for Windows 10 N.

https://support.microsoft.com/en-us/help/4562569/media-feature-pack-for-windows-10-n-may-2020

Update 16APR2024 : This option is nolonger available for Windows 10/11 N 22H2 series. The following will not work: DISM /Online /Add-Capability /CapabilityName:Media.MediaFeaturePack~~~~0.0.1.0

Adalia answered 23/1, 2019 at 6:40 Comment(8)
Using pip to install opencv-python==3.3.0.9 worked for me, thanks! I'm using Anaconda 3, python 3.5.6 on a Windows 10 machine.Medrano
Thanks a lot! After countless hours of searching, this was the good answer. On Windows 10 N, you need to install the media feature pack. Thanks a lot!Unsupportable
@AndrewThomas It was initially launched for Europe after their Non-Compete laws, but I have seen a few organizations outside of Europe adopt it since it doesn't contain bloatware.Adalia
Yes @Adalia You are correct. We were running Windows 10 N in the US and installing media pack fixed the issue.Paddock
After trying all of the options below (I didn't try this as I can't install mediafeaturepack on W2012-R2, and the opencv-python==3.3.0.9 doesn't install on Python 3.7), The only thing that worked was uninstalling 3.7, installing python 3.6, THEN running pip install opencv-python==3.3.0.9Aholla
As of May 2020, this appears to be the new way to install the media pack for windows 10 N. I have a system in production that used this answer, but I got an error missing a dll after a windows update. this fixed it. support.microsoft.com/en-us/help/4562569/…Paddock
I wrote the troubleshooting of opencv-dll-load-failed and media features pack was a problem on my end.Figurant
And also there is way to install via powershell dism, in my case a lifesaver since recommended MS or KB methods did not workErrick
C
8

I had the same error (although I compiled OpenCV myself), in my case there were some DLL dependencies missing. You can check that with the program Dependency Walker.

Download Dependency Walker and run it, and open the file cv2.pyd with Dependency Walker, it should be in C:\Program Files\Python37\lib\site-packages\cv2\ if the pip package installed correctly.

This program then scans for dependencies (which may take a few minutes) and it then shows missing DLL files in red.

Chane answered 15/9, 2018 at 23:46 Comment(3)
thanks for your reply,your answer made me hopeful, i wake up at 4 AM for testing your advice, i download dependency walker and download all warning(yellow ones) dll's (not Ext.MS.* and Api.MS.*) and put them in system32 , but still not work. i can't figure out whats wrong, i run opencv in 2 local system today and it work perfectly but in my remote server is not ok.Lentil
This Solution works! but you need add those .dll files to the metioned folder (...\lib\site-packages\cv2) not system32Cervine
for me mf.dll, mfplat.dll and mfreadwrite.dll where missing from win 2012Sow
G
7

I have faced the similar issue in Windows Server 2012 r2. 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 opencv would be available.

Grandstand answered 5/11, 2018 at 15:43 Comment(1)
I was getting the error on Windows Server 2012 R2. This saved me tons of time. Thanks! Although, had to restart the server.Hebraism
A
4

Python 3.7 may not support some modules.

  • Try installing python 3.6.4
  • Using command prompt, "pip install opencv" or "pip install opencv-python"
  • Import cv2
Auston answered 22/9, 2018 at 10:33 Comment(1)
Thanks man! I had the same problem and downgrading to 3.6.4 worked for me. But when do you think they will fix this by?Ayer
H
3

Can you try uninstalling opencv and installing it using a wheel file instead? Here is a website that has many versions of OpenCV compiled for windows, search for the one you need and simply install it with pip command.

So if you have Python 3.6 (64 Bit) and wish to install OpenCV 3.4.3 then download the wheel file: opencv_python‑3.4.3‑cp36‑cp36m‑win_amd64.whl

Herzig answered 17/9, 2018 at 15:39 Comment(1)
i test almost 10 of them ! but missing dll is appers on all of them.Lentil
L
3

I had similar issue except that I'm using Anaconda3 and this code here solved it:

conda install -c anaconda py-OpenCV
Latricialatrina answered 25/10, 2018 at 15:12 Comment(0)
V
2

After 15 days of brain storming, This solution worked for me. And I am sure that it will work for you too. I installed anaconda to use OpenCV 3.1.0. I followed following Steps:

1) I have installed anaconda-5.3 64-bit installer (614.3 MB) which uses python 3.7. You can download anaconda from link: https://www.anaconda.com/download/#windows

2) After installation of anaconda, open anaconda prompt by typing "anaconda prompt" on windows start button. Open with "Run as administrator".

3) You have to create new environment to install and use OpenCV module.Write following commands to create and activate new environment:
>conda create --name myNewEnv python=3.5.0
>activate myNewEnv
"myNewEnv" is the name of new enviroment.

4)Now you need to install prerequisite for OpenCV, which is numpy and then install opencv3. Start internet before executing following commands:
>conda install numpy
>conda install anaconda-client
>conda install --channel https://conda.anaconda.org/menpo opencv3

5)OpenCV3 has been installed. Now, verify installation by executing following commands:
(myNewEnv) C:\Users\Nilesh> python
>>>import cv2
>>>cv2.__version__

Follow steps given below, when you want to start OpenCV3 second time onwards:

1) Open "anaconda command promt" from start menu with "run as administrator" rights
2) Type command >activate your_new_environment_name
3) Assume that you want to run file located on desktop, for that write following command:
> cd C:\Users\Nilesh\Desktop
4) Now your working directory is Desktop.
5) Type following command to run any code (for example test.py).
> python test.py
Note: Here, python means version-3.

I hope this solution will work for you.

Volt answered 8/1, 2019 at 18:11 Comment(0)
P
2

I had the same problem on Windows Server 2012 R2 x64. I was creating executable file using PyInstaller and got error in runtime:

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

After installing "Visual C++ redistributable" 2015 and enabling "Media Foundation" feature my problem was resolved.

There is more informations in documentation: OpenCV Documentation

Perilune answered 2/3, 2020 at 11:36 Comment(0)
D
2

I was having this problem on Windows. I resolved this error by checking instructions here.

Q: Import fails on Windows: ImportError: DLL load failed: The specified module could not be found?

A: If the import fails on Windows, make sure you have Visual C++ redistributable 2015 installed. If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.

Windows N and KN editions do not include Media Feature Pack which is required by OpenCV. If you are using Windows N or KN edition, please install also Windows Media Feature Pack

Drubbing answered 28/7, 2021 at 20:9 Comment(0)
L
1

i was suffering from the same problem "DLL load failed" after reading tons of answers and articles i got a solution.

i don't know this works for you or not but give it a try.

tools and versions i used: anaconda - 5.3.1, python - 3.7, win 10 (64 bit)

Steps i performed :

step1:i installed opencv 3.4.4 from here then extract into C drive (you can do wherever you want)

step2: copy cv2.pyd file from [C:\opencv\build\python\cv2\python-3.7] here to [C:\Users\"user-name"\Anaconda3\Lib\site-packages] here.

step3: run dependency walker to detect which dll files are missing, after running dependency walker in my case it showed two dll files are not loading, they are (1)OPENCV_WORLD344.DLL and (2)IESHIMS.DLL. i don't know about your situation but you can do this-> find files name using dependency walker then find their path and follow step4.

step4: open System property->Advanced->Environment variables, now edit path and add C:\opencv\build\x64\vc14\bin (in my case this was the place where OPENCV_WORLD344.DLL is stored) and after doing this, import cv2 in python.

If my answer does not work then add a comment.

Lovett answered 23/11, 2018 at 14:33 Comment(0)
N
1

It helps me pip install opencv-contrib-python Anaconda Prompt, python 3.7.1 cv2 4.1.1

Negate answered 2/11, 2019 at 18:54 Comment(0)
H
1

I was having the same issue. I resolved this error by downgrading open cv.

pip install opencv-python==3.3.0.9

Headman answered 16/11, 2019 at 7:7 Comment(0)
C
0

its worked well for me.* Answer is Need to put cv2.pyd file to your virtual environment. need to put under two folder of envs,

  • first is under DLLS folder and Second is under Lib/site-packages

To get cv2.pyd > download from this link https://sourceforge.net/projects/opencvlibrary/ and then extract the download file

You will get opencv folder, after that go inside opencv folder like Downloads\opencv\build\python\2.7 and go one deeper folder depend on your 32 or 64 window version

Copy cv2.pyd Important **** after copying cv2.pyd file to your envs, you need to rename cv2.pyd to _cv2.pyd

Capello answered 12/4, 2019 at 4:1 Comment(0)
L
0

I was having this problem on Windows Server 2008R2 fresh install and took almost a day to resolve, as was trying with many hits and trials finally I found solution somewhere in internet (not stackoverflow)

  • Installed Windows Media Feature Pack for 2008R2 then installed Server Manager-> Features-> Add Features-> Desktop Experience
  • Server Manager-> Features-> Add Features-> Desktop Experience and Ink and Handwriting Services.

Besides check list includes

  • Visual C++ redistributable 2015
  • Universal C Runtime

Hopefully its will help save time

Ladin answered 5/12, 2019 at 9:56 Comment(0)
B
0

Installing Python version 3.6 and then installing opencv with the command: pip install opencv-python==3.3.0.9 resolved this issue for me

Bugloss answered 17/7, 2020 at 19:52 Comment(0)
B
0

All you need is python 3.6. I've been looking for solution for last 3 days and my problem was solved when i installed python 3.6.7. After installing python 3.6 you can simply run pip install opencv-python. Source: https://www.geeksforgeeks.org/setup-opencv-with-pycharm-environment/

Bombard answered 10/12, 2020 at 6:29 Comment(0)
U
0

Just ran into this problem of cv2 importable from my conda environment but not through the "same" environment in jupyter. The error I was getting was that it couldn't load the dll.

Additionally, I could not get opencv installed through jupyter, even using:

import sys
!conda install --yes --prefix {sys.prefix} numpy

I checked my path using:

import os
os.path

in both my shell and jupyter. They were the same(!).

I was finally able to get things working by running the command:

conda install nb_conda

in my conda environment, as outlined here: https://github.com/udacity/P1_Facial_Keypoints/issues/13

This was eye opening as it created a new install of jupyter note books associated with my env instead of anaconda, with five(!) environments to choose from when creating a page. There were three that seemed to be associated with my conda environment. Interestingly, now it only shows the one named environment as an option when creatin a new notebook again in jupyter (the one associated with the env), but it successfully imports cv2.

For a good read on why this is happening with jupyter: https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/

Unstained answered 24/8, 2021 at 16:29 Comment(0)
K
0

Came here from Windows 10N, upgraded to Windows 11. Had to install Media Feature Pack under Settings -> Apps -> Optional Features -> Add an optional feature.

Windows settings

Katlaps answered 1/5, 2022 at 19:26 Comment(0)
R
0

if anyone makes silly mistake as I have just done. I use python3.8 so cannot downgrade opencv by running pip install opencv-python==3.3.0.9 (I have not tried downgrading by whl)

to downgrade opencv by running pip install, you should use python3.6, and opencv 3.3.0.9 will solve DLL load failed

Ruhnke answered 20/5, 2023 at 17:13 Comment(0)
H
0

Answer as of May 2024. If you have Windows 11 and Python 3.12:

The solution that worked for me was to download this Windows Media Feature pack.

Make sure to download the Media Feature pack for your Windows OS version (mine is Windows 11 N). Also, make sure to restart your computer for the installation to complete.

Hilbert answered 12/5 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.