Python – Cannot find module cv2 when using OpenCV


I have installed OpenCV on the Occidentalis operating system (a variant of Raspbian) on a Raspberry Pi, using jayrambhia's script found here. It installed version 2.4.5.

When I try import cv2 in a Python program, I get the following message:

pi@raspberrypi~$ python
Traceback (most recent call last)
File "", line 1, in <module>
    import cv2
ImportError: No module named cv2

The file is stored in /usr/local/lib/python2.7/site-packages/...

There are also folders in /usr/local/lib called python3.2 and python2.6, which could be a problem but I'm not sure.

Is this a path error perhaps? Any help is appreciated, I am new to Linux.

Best Solution

First do run these commands inside Terminal/CMD:

conda update anaconda-navigator  
conda update navigator-updater  

Then the issue for the instruction below will be resolved

For windows if you have anaconda installed, you can simply do

pip install opencv-python


conda install -c opencv

if you are on linux you can do :

pip install opencv-python


conda install opencv 

Link1 Link2

For python3.5+ check these links : Link3 , Link4

if you use anaconda, you may simply use this as well (and hence don't need to add menpo channel):

conda install -c conda-forge opencv
Related Question