Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anaconda: cannot import cv2 even though opencv is installed (how to install opencv3 for python3)

I have Anaconda (version: conda 4.2.9, python3) installed and am trying to do import cv2 when I get the following error:

ImportError: No module named 'cv2'

With conda search cv2 I get this:

  opencv                     2.4.2                np15py26_0  defaults        
                             2.4.2                np15py27_0  defaults        
                             2.4.2                np16py26_0  defaults        
                             2.4.2                np16py27_0  defaults        
                             2.4.2                np17py26_0  defaults        
                             2.4.2                np17py27_0  defaults        
                             2.4.2                np15py26_1  defaults        
                             2.4.2                np15py27_1  defaults        
                             2.4.2                np16py26_1  defaults        
                             2.4.2                np16py27_1  defaults        
                             2.4.2                np17py26_1  defaults        
                             2.4.2                np17py27_1  defaults        
                             2.4.6                np16py26_0  defaults        
                             2.4.6                np16py27_0  defaults        
                             2.4.6                np17py26_0  defaults        
                             2.4.6                np17py27_0  defaults        
                             2.4.6                np18py26_0  defaults        
                             2.4.6                np18py27_0  defaults        
                             2.4.9                np18py27_0  defaults        
                             2.4.10               np19py26_0  defaults        
                             2.4.10               np19py27_0  defaults        
                             2.4.10              np110py27_1  defaults        
                             2.4.10               np19py26_1  defaults        
                             2.4.10               np19py27_1  defaults        

What do I need to do to be able to import the cv2 module?

I am using Ubuntu 16.04.

like image 520
Linda Avatar asked Oct 11 '16 12:10

Linda


People also ask

How do I import cv2 in Anaconda prompt?

Step 1:- After installing the anaconda open the Anaconda Prompt. Step 2:- Type the given command, press enter, and let it download the whole package. Step 3:- Now simply import OpenCV in your python program in which you want to use image processing functions.

Why import cv2 is not working?

Conclusion # The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.

How do I download cv2 in python 3?

Open the terminal in your system. Start the Python shell by typing python3 and then hit enter. You will be inside the Python shell where you can execute your Python code. Import the cv2 package which is the name of the OpenCV module.


2 Answers

opencv is not compatible with python 3. I had to install opencv3 for python 3. The marked answer in how could we install opencv on anaconda? explains how to install opencv(3) for anaconda:

Run the following command:

conda install -c https://conda.binstar.org/menpo opencv

I realized that opencv3 is also available now, run the following command:

conda install -c https://conda.binstar.org/menpo opencv3

Edit on Aug 18, 2016: You may like to add the "menpo" channel permanently by:

conda config --add channels menpo

And then opencv can be installed by:

conda install opencv (or opencv3)

Edit on Aug 14, 2017: "clinicalgraphics" channel provides relatively newer vtk version for very recent python3

conda install -c clinicalgraphics vtk

Edit on April 16, 2020 (based on @AMC's comment): OpenCV can be installed through conda-forge (details see here)

conda install -c conda-forge opencv

like image 86
Linda Avatar answered Oct 01 '22 12:10

Linda


You can try

conda install -c menpo opencv=3
like image 20
Hong Avatar answered Oct 01 '22 12:10

Hong