Question

[Solved] “DLL load failed” when import cv2 (opencv)

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 FilesPython37libsite-packagescv2__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)

Solution #1:

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

Respondent: anand_v.singh

Solution #2:

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 FilesPython37libsite-packagescv2 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.

Respondent: cuzi

Solution #3:

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.

Respondent: Biks

Solution #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
Respondent: Vikhyat Agarwal

Solution #5:

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

Respondent: Rakshith G B

Solution #6:

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

conda install -c anaconda py-OpenCV
Respondent: Omda asli

Solution #7:

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:UsersNilesh> 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:UsersNileshDesktop
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.

Respondent: Nell

Solution #8:

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

Respondent: luka_matkic

Solution #9:

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:opencvbuildpythoncv2python-3.7] here to [C:Users”user-name”Anaconda3Libsite-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:opencvbuildx64vc14bin (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.

Respondent: Rhythm sharma

Solution #10:

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

pip install opencv-python==3.3.0.9

Respondent: Faizi

Solution #11:

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 Downloadsopencvbuildpython2.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

Respondent: kaythi swetun

Solution #12:

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

Respondent: sergemart

Solution #13:

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

Respondent: Sandip Bantawa

Solution #14:

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

Respondent: Vishnu

Solution #15:

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/

Respondent: user14799067

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy