asheeshr
asheeshr

Reputation: 4114

Installing OpenCV for Python in Ubuntu 12.04. No module present in dist-packages or site-packages?

Following the steps given here, i have completed the installation process, however Python (IDLE) is giving me an ImportError. For which the guide suggests :

Python may return to you an error like "No module named cv" The trouble is that the python module is installed in /usr/local/lib/python2.6/site-packages. But, on Debian and on Ubuntu, Python only looks in /usr/local/lib/python2.6/dist-packages

You can fix it using three ways (Use only one of those, the first is the best):

  1. move the cv.so file from the site-packages to the dist-packages:

    sudo mv /usr/local/lib/python2.6/site-packages/cv.so /usr/local/lib/python2.6/dist-packages/cv.so

However, both the site-packages as well as dist-packages, for both 2.7 and 3.2 are empty.

What went wrong and how do i solve it ?

Upvotes: 5

Views: 15039

Answers (2)

asheeshr
asheeshr

Reputation: 4114

I solved the problem by installing all the packages and dependencies again using the Software Center. OpenCV Python bindings are available for OpenCV 2.3 and Python 2.7 directly from the software center which I used the second time.

OpenCv python bindings for 3.2 are not available for 12.04. They are being developed for Raring (Ubuntu 13.04) only. Hence, the solution is to use either backports, or to use OpenCv on Python 2.7

Backports also have a problem as they are available only for 32 bit OS systems and not 64 bit.

So, the only safe and stable way to run OpenCV Python on Ubuntu seems to be using OpenCV 2.3 on Python 2.7

Upvotes: 4

Thai Tran
Thai Tran

Reputation: 9935

I also get the empty dist-packages folder with OpenCV2.4.4 and Ubuntu 12.04. It turns out that I need to install python-dev and python-numpy in order to make the cv.so compiled into the dist-packages.

sudo apt-get install python-dev python-numpy

After that, using cmake to build OpenCV again and everything will be fine

UPDATE it depends on your system pretty much.

  • On my Lion (10.8), I have java installed, and openCV complaints about cannot build the unit test and stop at 92%. It turned out that I have to manually create the build folder and put the junit jar into the lib folder in order to let opencv compile all the test case. After that, everything is ok
  • On my ubuntu (12.04, fresh installation with build-essential and all packages are up-to-date), eveything is compiled fine, except that "No module named cv" and there is not cv.so in the dist-packages and site-packages. Searching around and then finally, it turned out that I have to have python-dev and python-numpy

Upvotes: 2

Related Questions