Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 877
robm Avatar asked Aug 09 '14 04:08

robm


People also ask

How do I fix No module named cv2 in python?

importerror no module named cv2 error occurs when cv2 module is not properly installed or its path is not properly set or configured. The straight way fix for this error (no module named cv2) is to reinstall this module (OpenCV-python). In some scenario reinstalling this module automatically remove the older version.


1 Answers

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

like image 137
ozguronur Avatar answered Sep 20 '22 19:09

ozguronur