0

I ran the following command on terminal

$ sudo apt-get install libopencv-dev python-opencv

This installed opencv version 2.4.10.

After that I open python in terminal and try to import opencv as follows

>> import cv2

This gives me an error :

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2

I also tried using import cv, import opencv, etc. but I am getting the same error. Do I need to follow some more steps to configure opencv for python ??

Aalok_G
  • 471
  • 7
  • 18
  • Check if this answers your problem [Installing OpenCV for Python on Ubuntu, getting ImportError: No module named cv2.cv](http://stackoverflow.com/questions/25215102/installing-opencv-for-python-on-ubuntu-getting-importerror-no-module-named-cv2) – Bhargav Rao Jul 21 '15 at 16:40

6 Answers6

0

Try using this:

sudo apt-get install python-opencv opencv-dev python-numpy python-dev
Melebius
  • 6,183
  • 4
  • 39
  • 52
Yuvraj Gupta
  • 2,475
  • 16
  • 26
0

This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries

Add these lines in the code:

import sys

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

or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.

OR

try adding the following line in ~/.bashrc

export PATH=/usr/local/lib/python2.7/site-packages:$PATH
iec2011007
  • 1,828
  • 3
  • 24
  • 38
0

This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries

Add these lines in the code:

import sys

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

or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.

iec2011007
  • 1,828
  • 3
  • 24
  • 38
0

I think it is better that you just install Anaconda python distribution.

https://www.continuum.io/downloads

You can find wealth of tutorials in the internet on how to install it in your system. And trust me, it is VERY EASY to install.

After you have install your Anaconda python distribution, you can install OpenCV 3.1 by the following commands. Note that you should have an internet connection.

# if you are using Anaconda for Python 2.7
conda install -c menpo opencv

The above code should install OpenCV 3.1 in your anaconda python 2.7

# if you are using Anaconda for Python 3.5
conda install -c menpo opencv3

The above code should install OpenCV 3.1 in your anaconda python 3.5

Then to verify that you have successfully install OpenCV 3.1 in your system, you can issue the following command in the python interpreter:

# import the opencv library
import cv2

# prints the version of the OpenCV installed in your system
cv2.__version__

That's it. I hope that helped you =)

stevenferrer
  • 2,504
  • 1
  • 22
  • 33
0

There is an installer for Ubuntu 16.04, and it may work well on Ubuntu 14.04, you could have a try. I have used it to install on Ubuntu 16.04 and it succeed!

An interactive installing script for install openCV on Ubuntu 16.04 LTS

orange
  • 1
  • 2
0

The Opencv version(2.4.10) installed is for python2x version.
I think you are trying to use cv2 in python3x version (which might be set as default for python)
Open python2 on terminal (use command python2 instead of python)

>> import cv2

This will work.

alphaguy
  • 540
  • 3
  • 17