opencv-python: DLL load fails on Anaconda/Windows install (python3.dll)
After doing a simple pip install opencv-python
or pip install opencv-contrib-python
and trying to import the library, I ran into this issue:
λ python
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: The specified module could not be found.
The readme suggests installing the Visual C++ Redistributable for Visual Studio 2015 but I already had it installed (actually had Visual Studio itself installed as well).
Checking the dependencies of the pyd binary in this package (using dumpbin which comes with Visual Studio):
λ dumpbin.exe C:\Anaconda3\Lib\site-packages\cv2\cv2.cp35-win_amd64.pyd /IMPORTS | grep dll
python3.dll
python35.dll
MSVFW32.dll
AVIFIL32.dll
AVICAP32.dll
KERNEL32.dll
USER32.dll
GDI32.dll
ole32.dll
OLEAUT32.dll
COMDLG32.dll
ADVAPI32.dll
After checking if these were in the PATH I was surprised to find that python3.dll
was the only one that wasn’t!
Although python3.dll
comes with the standard CPython install, it’s not packaged with Anaconda for some reason. ContinuumIO/anaconda-issues#1394 references this and it seems like it’s just not supported(?).
As a workaround suggested in that thread, I solved this by just copying python3.dll
from the official CPython 3.5.2 binaries (specifically from the Windows x86-64 embeddable zip file) into C:\Anaconda3
, although I imagine it would work being anywhere in your PATH.
I thought I’d share this bit of troubleshooting since Anaconda is a popular distribution among academics and so is OpenCV, so I figure I might not be the only one running into this issue. Maybe a note in the readme might help others until Anaconda resolves this?
Alternatively, the menpo/opencv3 Anaconda package would also work but I don’t think it supports ffmpeg nor opencv-contrib.
For reference, I’m running on Python 3.5.2 which came with Anaconda 4.2.0 (official installer), although conda info
reports a slightly newer version:
λ conda info
Current conda install:
platform : win-64
conda version : 4.3.16
conda is private : False
conda-env version : 4.3.16
conda-build version : 2.0.2
python version : 3.5.2.final.0
requests version : 2.12.4
root environment : C:\Anaconda3 (writable)
default environment : C:\Anaconda3
envs directories : C:\Anaconda3\envs
C:\Users\Talmo\AppData\Local\conda\conda\envs
C:\Users\Talmo\.conda\envs
package cache : C:\Anaconda3\pkgs
C:\Users\Talmo\AppData\Local\conda\conda\pkgs
channel URLs : https://repo.continuum.io/pkgs/free/win-64
https://repo.continuum.io/pkgs/free/noarch
https://repo.continuum.io/pkgs/r/win-64
https://repo.continuum.io/pkgs/r/noarch
https://repo.continuum.io/pkgs/pro/win-64
https://repo.continuum.io/pkgs/pro/noarch
https://repo.continuum.io/pkgs/msys2/win-64
https://repo.continuum.io/pkgs/msys2/noarch
config file : None
offline mode : False
user-agent : conda/4.3.16 requests/2.12.4 CPython/3.5.2 Windows/10 Windows/10.0.15063
Cheers and thanks for all the work you put into this repo!
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 44
- Comments: 29 (9 by maintainers)
i meet the same problem, and i solve it from stackoverflow: https://stackoverflow.com/questions/43184887/dll-load-failed-error-when-importing-cv2
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, type python --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 to Anaconda3 folder
I install a totally new windows 7 system,and I encountered the same problem as well.Then I find the dll below in other machine ,put it into C:\Windows\System32, and I solve the import cv2 problem. my test machine info:windows 7 ultimate;Anaconda 5.0.1. api-ms-win-downlevel-shlwapi-l1-1-0.dll
Yea kinda got out of hand. Sorry for that. Do hope this dialogue would be helpful to at least 1 other person.
use conda update -all to get a stable environment. Then everything will be alright.
Thank you very much.
Yes, it’s on Windows. And the method in this website solved my problem. https://www.scivision.co/install-opencv-python-windows/
Previously, I installed opencv using
conda install opencv
, while now I useconda install -c conda-forge opencv
.