0

After installing OpenCV via pip on Windows 10 with:

pip install opencv-python

I can not import the module. When executing the command:

import cv2

I get the error:

File "C:\ProgramData\Anaconda3\lib\site-packages\cv2__init__.py", line 7, in from . import cv2

ImportError: DLL load failed:...

If I look into the file throwing the code, it looks like the following:

import sys
import os

# FFMPEG dll is not found on Windows without this
os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__))

from . import cv2
sys.modules['cv2'] = cv2

So I guess it is ffmpeg which is missing. Thus I installed ffmpeg like described here: http://www.wikihow.com/Install-FFmpeg-on-Windows

Thus, ffmpeg is in my path. However, the error message still occurs. I also tried to install the ffmpeg via pip with

pip install ffmpeg-normalize

But this did not help either.

Kev1n91
  • 3,553
  • 8
  • 46
  • 96
  • 1
    Check answers in this [dll-load-failed-error-when-importing-cv2](https://stackoverflow.com/questions/43184887/dll-load-failed-error-when-importing-cv2/43190144#43190144) and this [installing-opencv-on-windows-10-with-python-3-6-and-anaconda-3-6](https://stackoverflow.com/questions/42994813/installing-opencv-on-windows-10-with-python-3-6-and-anaconda-3-6/43022332#43022332). They might help. – thewaywewere Jun 20 '17 at 17:44

1 Answers1

1

The opencv-python Windows packages ship with FFmpeg by default. You can have a look at C:\ProgramData\Anaconda3\lib\site-packages\cv2 and you should find FFmpeg DLL there. You don't have to install it separately.

The real problem lies most probably in Anaconda because they are not shipping python3.dll with their distribution. This is required by PEP 384. Related Anaconda issue is here: https://github.com/ContinuumIO/anaconda-issues/issues/1394

To fix this, you will have to copy python3.dll from a CPython installer package and place it to PATH. The CPython version must match your Anaconda version. Easiest way is to copy the file to some place which is already in PATH. This could be for example C:\Anaconda3 if that's where your Anaconda installation is located.

If the above does not work, make sure that you have Visual C++ redistributable 2015 installed: https://www.microsoft.com/en-us/download/details.aspx?id=48145

skvark
  • 2,193
  • 2
  • 16
  • 12