Installing OpenCV for Python on Ubuntu, getting ImportError: No module named cv2.cv

robm picture robm · Aug 9, 2014 · Viewed 222.3k times · Source

I have an Ubuntu 14.04 system, on which I want to install OpenCV and use it with Python 2.x.

I installed OpenCV using the instructions here: https://help.ubuntu.com/community/OpenCV

The install seemed to run properly, no errors, the script ended with output

OpenCV 2.4.9 ready to be used

When I try to run the sample Python script, I get the following:

$ python opencv.py
Traceback (most recent call last):
  File "opencv.py", line 1, in <module>
    from cv2.cv import *
ImportError: No module named cv2.cv

I suspect I know why, I just don't know how to fix it. OpenCV installed to the current directory I was in when I ran the install script, it's a subdirectory of my home folder.

Others who get this import error after install seem to be having a path issue, and have luck adding this to their code:

import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')

or updating their PYTHONPATH with that same directory. I tried adding that code, it doesn't make a difference. I don't see any files in the "site-packages" directory. Should I have done the install in that directory? I imagine the installation instructions would have spelled that out. I suspect that my problem has to do with Python not finding the OpenCV install, but I'm not sure how to proceed.

Please help me get a usable install of OpenCV as simply as possible.

Answer

ozguronur picture ozguronur · Mar 24, 2015

I think you don't have the python-opencv package.

I had the exact same problem and

sudo apt-get install python-opencv

solved the issue for me.

you can install opencv from the following link https://www.learnopencv.com/install-opencv3-on-ubuntu/ It works for me . apt-get install doesnt contain many packages of opencv