OpenCV-Python ImportError: DLL load failed: The specified module could not be found
Question:
I am working on windows 10 with Python 3.6.0 (Anaconda3) and jupyter notebook. I have successfully installed and imported OpenCV-Python with the help of comments in this post.
Now the problem is that If I am importing opencv (ijmport cv2) from the same command prompt where I installed the opencv, it is importing without any error.
But if I am importing opencv from another command prompt, then it is giving me this error:
ImportError: DLL load failed: The specified module could not be found.
I can’t attach any picture to show this as my reputation is 3. So I am explaining it here.
Command Prompt1:
C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>pip install opencv_python-3.2.0+contrib-cp36-cp36m-
win_amd64.whl
Processing C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>pip install opencv_python-3.2.0+contrib-cp36-cp36m-
win_amd64.whl
Installing collected packages: opencv-python
Found existing installation: opencv-python-3.2.0.7
Uninstalling opencv-python-3.2.0.7:
Successfully uninstalled opencv-python-3.2.0.7
Successfully installed opencv-python-3.2.0+contrib
C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>python
Python 3.2.0 |Anaconda4.3.1(64-bit)| (default, Dec 23 2016, 11:47:51) [MSC
v.1900 64-bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>import cv2
>>>
Command Prompt2:
C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>python
Python 3.2.0 |Anaconda4.3.1(64-bit)| (default, Dec 23 2016, 11:47:51) [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:UsersPrachiAnaconda3libsite-packagescv2__init__.py", line 7,
in <module>
from . import cv2
ImportError: DLL load failed: The specified module could not be found.
>>>
This is why, whenever I am opening new command prompt to start coding, I have to install opencv again and then use it.
Hope this explaination helps in understanding the problem.
Answers:
You may try this conda install
command for installing OpenCV 3.2.0
for Python 3.6
. The conda-forge
repository does have OpenCV 3.2.0
binary for 32-bit
and 64-bit
Windows.
conda install -c conda-forge opencv=3.2.0
If you need opencv_contrib modules, you can download the binary from this unoffice website and install it to Anaconda
through pip install
.
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win32.whl
(x86 Win)
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
(x64 Win)
Take note the package installed by pip will not be shown by conda list
command.
Then type import cv2
in command prompt to verify if the installation is success as below.
If you have problem on import cv2
, double check Windows Environment Variables
setup as below.
OPENCV_DIR
points to your OpenCV
executable files, e.g. C:Program FilesOpenCV 3.2.0x64vc14
PATH=%PATH%;%OPENCV_DIR%bin
I solved it accidentally by doing these things:
Navigated to the Anaconda installation directory:
cd C:UsersPrachi.................Anaconda3Scripts
Installed opencv from conda-forge
repository
conda install -c conda-forge opencv
This installed OpenCV 3.2.0-np113py36_203 conda-forge
In the same command prompt, I typed jupyter notebook
.
And import cv2
executed successfully in the jupyter notebook window.
C:UsersAdmin>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
import cv2
Traceback (most recent call last):
File "", line 1, in
File "C:UsersAdminac3libsite-packagescv2_init_.py", line 5, in
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
pip install cv
File "", line 1
pip install cv
^
SyntaxError: invalid syntax
pip install opencv
File "", line 1
pip install opencv
^
SyntaxError: invalid syntax
exit()
C:UsersAdmin>pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
WARNING: Requirement ‘opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl’ looks like a filename, but the file does not exist
ERROR: opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl is not a valid wheel filename.
C:UsersAdmin>opencv-python
‘opencv-python’ is not recognized as an internal or external command,
operable program or batch file.
C:UsersAdmin>pip install opencv-python
Requirement already satisfied: opencv-python in c:usersadminac3libsite-packages (4.5.1.48)
Requirement already satisfied: numpy>=1.14.5 in c:usersadminac3libsite-packages (from opencv-python) (1.19.5)
C:UsersAdmin>
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagescv2_init_.py", line 3, in
from .cv2 import *
ImportError: DLL load failed: Le module sp�cifi� est introuvable.
I am working on windows 10 with Python 3.6.0 (Anaconda3) and jupyter notebook. I have successfully installed and imported OpenCV-Python with the help of comments in this post.
Now the problem is that If I am importing opencv (ijmport cv2) from the same command prompt where I installed the opencv, it is importing without any error.
But if I am importing opencv from another command prompt, then it is giving me this error:
ImportError: DLL load failed: The specified module could not be found.
I can’t attach any picture to show this as my reputation is 3. So I am explaining it here.
Command Prompt1:
C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>pip install opencv_python-3.2.0+contrib-cp36-cp36m-
win_amd64.whl
Processing C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>pip install opencv_python-3.2.0+contrib-cp36-cp36m-
win_amd64.whl
Installing collected packages: opencv-python
Found existing installation: opencv-python-3.2.0.7
Uninstalling opencv-python-3.2.0.7:
Successfully uninstalled opencv-python-3.2.0.7
Successfully installed opencv-python-3.2.0+contrib
C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>python
Python 3.2.0 |Anaconda4.3.1(64-bit)| (default, Dec 23 2016, 11:47:51) [MSC
v.1900 64-bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>import cv2
>>>
Command Prompt2:
C:UsersPrachiAppDataLocalProgramsPythonPython36-
32Anaconda3Scripts>python
Python 3.2.0 |Anaconda4.3.1(64-bit)| (default, Dec 23 2016, 11:47:51) [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:UsersPrachiAnaconda3libsite-packagescv2__init__.py", line 7,
in <module>
from . import cv2
ImportError: DLL load failed: The specified module could not be found.
>>>
This is why, whenever I am opening new command prompt to start coding, I have to install opencv again and then use it.
Hope this explaination helps in understanding the problem.
You may try this conda install
command for installing OpenCV 3.2.0
for Python 3.6
. The conda-forge
repository does have OpenCV 3.2.0
binary for 32-bit
and 64-bit
Windows.
conda install -c conda-forge opencv=3.2.0
If you need opencv_contrib modules, you can download the binary from this unoffice website and install it to Anaconda
through pip install
.
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win32.whl
(x86 Win)pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
(x64 Win)
Take note the package installed by pip will not be shown by conda list
command.
Then type import cv2
in command prompt to verify if the installation is success as below.
If you have problem on import cv2
, double check Windows Environment Variables
setup as below.
OPENCV_DIR
points to yourOpenCV
executable files, e.g.C:Program FilesOpenCV 3.2.0x64vc14
PATH=%PATH%;%OPENCV_DIR%bin
I solved it accidentally by doing these things:
Navigated to the Anaconda installation directory:
cd C:UsersPrachi.................Anaconda3Scripts
Installed opencv from conda-forge
repository
conda install -c conda-forge opencv
This installed OpenCV 3.2.0-np113py36_203 conda-forge
In the same command prompt, I typed jupyter notebook
.
And import cv2
executed successfully in the jupyter notebook window.
C:UsersAdmin>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
import cv2
Traceback (most recent call last):
File "", line 1, in
File "C:UsersAdminac3libsite-packagescv2_init_.py", line 5, in
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
pip install cv
File "", line 1
pip install cv
^
SyntaxError: invalid syntax
pip install opencv
File "", line 1
pip install opencv
^
SyntaxError: invalid syntax
exit()
C:UsersAdmin>pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
WARNING: Requirement ‘opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl’ looks like a filename, but the file does not exist
ERROR: opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl is not a valid wheel filename.
C:UsersAdmin>opencv-python
‘opencv-python’ is not recognized as an internal or external command,
operable program or batch file.
C:UsersAdmin>pip install opencv-python
Requirement already satisfied: opencv-python in c:usersadminac3libsite-packages (4.5.1.48)
Requirement already satisfied: numpy>=1.14.5 in c:usersadminac3libsite-packages (from opencv-python) (1.19.5)
C:UsersAdmin>
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagescv2_init_.py", line 3, in
from .cv2 import *
ImportError: DLL load failed: Le module sp�cifi� est introuvable.