Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python can't find openCV

I just ran the script to install OpenCV. I'm running Linux here. I installed it after much struggle but it finally has completed. That being said, for some reason, it still isn't working. I've never had this much trouble installing a package in my life. Here are the last few lines of my terminal:

**********************************************************************

 Done. The new package has been installed and saved to

 /home/myname/Desktop/OpenCV/opencv-2.4.9/build/build_20140812-1_i386.deb

 You can remove it from your system anytime using: 

      dpkg -r build

**********************************************************************

OpenCV 2.4.9 ready to be used
me:~/Desktop$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv2

anyone have any ideas why it's not working? thanks

like image 476
Sam Creamer Avatar asked Feb 13 '23 06:02

Sam Creamer


1 Answers

From openCV - python installation manual:

After installing:

Installation is over. All files are installed in /usr/local/ folder. But to use it, your Python should be able to find OpenCV module. You have two options for that. Move the module to any folder in Python Path : Python path can be found out by

entering import sys;print sys.path in Python terminal. It will print out many locations. Move /usr/local/lib/python2.7/site-packages/cv2.so to any of this folder. For example,

    su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages

But you will have to do this every time you install OpenCV.

Add /usr/local/lib/python2.7/site-packages to the PYTHON_PATH: It is to be done only once. Just open ~/.bashrc and add following line to it, then log out and come back.

    export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

Thus OpenCV installation is finished. Open a terminal and try import cv2.

Note that your python version or library location may be different.

like image 112
cerkiewny Avatar answered Feb 15 '23 02:02

cerkiewny