2

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:\Users\Prachi\AppData\Local\Programs\Python\Python36-
32\Anaconda3\Scripts>pip install opencv_python-3.2.0+contrib-cp36-cp36m-
win_amd64.whl
Processing C:\Users\Prachi\AppData\Local\Programs\Python\Python36-
32\Anaconda3\Scripts>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:\Users\Prachi\AppData\Local\Programs\Python\Python36-
32\Anaconda3\Scripts>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:\Users\Prachi\AppData\Local\Programs\Python\Python36-
32\Anaconda3\Scripts>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:\Users\Prachi\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.
>>>

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.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Prachi
  • 141
  • 2
  • 2
  • 13
  • What error do you get when trying to install opencv-python in your Anaconda prompt? – BoboDarph Jun 21 '17 at 07:46
  • The error was: FileNotFoundError: The file is not found in current win64 channels. I downloaded opencv from this link http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv I tried 32, 64-bit, contrib+ each type but for every file, above error was there. – Prachi Jun 21 '17 at 10:09
  • If pip install opencv-python fails in the anaconda prompt, you can try manually installing opencv3 following instructions here https://stackoverflow.com/questions/38787748/installing-opencv-3-1-with-anaconda-python3 or here https://rivercitylabs.org/up-and-running-with-opencv3-and-python-3-anaconda-edition/ . One more observation: from the comments I understand that there is no support for 32-bit linux systems. – BoboDarph Jun 21 '17 at 10:19
  • pip install opencv-python successfully installed opencv. but when I wrote import cv2 in jupyter notebook, this error came - ImportError: DLL load failed: The specified module could not be found. – Prachi Jun 21 '17 at 10:53
  • I don't know if jupyter notebook knows how to use the python interpreter that anaconda manages. If your pip installation works, then the problem is most likely that whatever IDE you use yo run your code doesn't know where the Anaconda python interpreter is. – BoboDarph Jun 21 '17 at 10:59
  • From this site https://stackoverflow.com/questions/38787748/installing-opencv-3-1-with-anaconda-python3 , I tried solutions but got this error: UnsatisfiableError: The following specifications were found to be in conflict: - opencv 3 -> python 2.7 - python 3.6 Use "conda info " to see the dependencies for each package. – Prachi Jun 21 '17 at 11:04
  • This error of conflict came several times before. For this I downgraded to python 2.7 virtually but it remained there. If it is the case of IDE doesn't know about interpreter, then how to check it? – Prachi Jun 21 '17 at 11:08
  • Could you try, in your anaconda prompt, using pip, to upgrade python to 3.5 and then install opencv3? The last answer in the stackoverflow questions hints to the fact that this approach worked for the commenter. If all else fails, go nuclear on it's ass and either install it from source (Linux) or prebuilt binaries (windows) in this tutorial https://breakthrough.github.io/Installing-OpenCV/ – BoboDarph Jun 21 '17 at 12:40
  • I typed in the command prompt: C:\Users\Prachi.................\Anaconda3\Scripts>> conda install -c conda-forge opencv This installed OpenCV 3.2.0-np113py36_203 conda-forge and the in the same command prompt I typed jupyter notebook. By this import cv2 was successful when wrote in Jupyter notebbok. – Prachi Jun 21 '17 at 13:14

3 Answers3

4

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. enter image description here

If you have problem on import cv2, double check Windows Environment Variables setup as below.

  1. OPENCV_DIR points to your OpenCV executable files, e.g. C:\Program Files\OpenCV 3.2.0\x64\vc14
  2. PATH=%PATH%;%OPENCV_DIR%\bin
thewaywewere
  • 8,128
  • 11
  • 41
  • 46
  • I did this also: pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl But when I am installing opencv whether by this method or by the method of conda-forge stated above by me, import cv2 is successful when I am opening jupyter notebook from the same command prompt. But when I am opening jupyter notebook from new command prompt, this is giving me this error again - ImportError: DLL load failed: The specified module could not be found. Do I have to always install opencv first n then start jupyter notebook? It is very time consuming. – Prachi Jun 21 '17 at 14:15
  • Can you continue to code and run `opencv` script at the first launched Jupyter? If you can use the first Jupyter for `opencv', why you have to launch the second instant? You can run multiple notebooks `.ipymb` from the web or same instant. – thewaywewere Jun 21 '17 at 15:01
  • Yes this is the case, when I am working from the same command prompt, I am able to work using cv2 i.e import cv2 works but when I run jupyter notebook from other command prompt it gives me that dll error. The way you suggested to verify in the command prompt whether it is a success is not. This works on the command prompt on which I installed opencv but when I am opening other and writing import cv2, it is giving me the same error. I can't understand the reason. – Prachi Jun 21 '17 at 16:25
  • @Prachi see my updated answer. By the way, your question didn't clearly specify the issue you commented here. Would suggest you to supplement your question with more information in a clear context. Adding screenshot would help all the reviewer to understand the issue you encountered. – thewaywewere Jun 21 '17 at 16:46
  • @Prachi it's weird. Suggest you to create a new virtual environment in Anaconda then install OpenCV to avoid any conflict. Or uninstall Anaconda to refresh everything and try again. – thewaywewere Jun 21 '17 at 18:06
  • Ok I will try it. – Prachi Jun 21 '17 at 18:44
  • It looks promising, but I got error: failed UnsatisfiableError: The following specifications were found to be incompatible with the existing python installation in your environment: Specifications: - opencv=3.2.0 -> python[version='2.7.*|3.5.*|3.6.*'] Your python: python=3.7. What version should be for python 3.7 though?? Newest doesn't work. – Peter.k Feb 08 '23 at 20:08
  • 1
    @Peter.k From the [unofficial website](https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv), it shows OpenCV 4.5.5 supports CPython3.7, such as `opencv_python‑4.5.5+mkl‑cp37‑cp37m‑win_amd64.whl`. – thewaywewere Feb 11 '23 at 15:21
  • @thewaywewere Yes, this works, but those first link, not with +mkl. There was an issue with numpy version while importing cv2. I uninstalled conda ver. 1.16 and installed it with pip 1.21, so probably I may expect some incompabilities during work, but for now everything works. – Peter.k Feb 11 '23 at 15:44
2

I solved it accidentally by doing these things:

Navigated to the Anaconda installation directory:

cd C:\Users\Prachi.................\Anaconda3\Scripts

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.

Rohit Lal
  • 2,791
  • 1
  • 20
  • 36
Prachi
  • 141
  • 2
  • 2
  • 13
1

C:\Users\Admin>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:\Users\Admin\ac3\lib\site-packages\cv2_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:\Users\Admin>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:\Users\Admin>opencv-python 'opencv-python' is not recognized as an internal or external command, operable program or batch file.

C:\Users\Admin>pip install opencv-python Requirement already satisfied: opencv-python in c:\users\admin\ac3\lib\site-packages (4.5.1.48) Requirement already satisfied: numpy>=1.14.5 in c:\users\admin\ac3\lib\site-packages (from opencv-python) (1.19.5)

C:\Users\Admin>