Python opencv macport bindings

using the OpenCV installation for MacPorts, it seems like you don't need to install python bindings anywhere. Are they included where they go?

+7
python opencv macports
source share
5 answers

Have you chosen the + python26 option for the MacPorts port ?

$ sudo port install opencv +python26 
+10
source share

I had the same problem. OpenCV Python bindings seem to be built and installed, but they are not listed in the site-packages directory. I found a solution by adding a symlink to the embedded file "cv.so" in the "site-packages" directory of the Python package installed by MacPorts. These instructions are tested during setup using Mac OS 10.6.6. MacPorts object packages are python27 and opencv.

To make sure that the Python bindings are actually on your disk, you need to make sure that you invoke the opencv package with the python option:

 sudo port install opencv +python27 

The cv.so shared object file will be created in the following directory:

 /opt/local/@@PYTHON_PKGD@@ 

You will need to create a symbolic link in the Python "site-packages" directory. You can find the path to this directory by executing these commands in the Python interpreter:

 from distutils.sysconfig import get_python_lib print get_python_lib() 

The returned path should look like the following:

 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 

Create a symbolic link to the shared object ("cv.so") in this directory:

 ln -s /opt/local/@@PYTHON_PKGD@@/cv.so /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv.so 

Now you can import the cv module into your interpreter:

 import cv 

Your installation may be slightly different if you are using a different version of Python or OpenCV; however, the general methodology should be the same, with the exception of path names. There may be a better way to do this, but this methodology works well.

+7
source share

This should be set to

 /Library/Python/2.6/site-packages 

if you use sudo install port.

Directories 2.6, 2.5 .. will depend on the version of python in the path.

Thanks Ned, the fix above is mac os x distribution.

Macports has it all:

/opt/local/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages

+1
source share

be sure to install py26-numpy to support basic functions like cv.fromarray :

 sudo port install py26-numpy 

opencv will automatically compile without numpy (this is not strictly a dependency).

 sudo port install -v opencv +python26 

there you can check that numpy binding is effective.

+1
source share

Here is what I had to do:

STEP ONE

Use Macports to install opencv.

STEP TWO strong>

Put these two files somewhere on your PYTHONPATH (e.g. in site-packages ):

STEP THREE

Create the links below (because cv2.so expects dylib to be in /usr/local , but MacPorts is installed on /opt/local ):

 cd /usr/local/lib/ ln -s /opt/local/lib/libopencv_core.2.3.dylib libopencv_core.2.3.dylib ln -s /opt/local/lib/libopencv_flann.2.3.dylib libopencv_flann.2.3.dylib ln -s /opt/local/lib/libopencv_imgproc.2.3.dylib libopencv_imgproc.2.3.dylib ln -s /opt/local/lib/libopencv_video.2.3.dylib libopencv_video.2.3.dylib ln -s /opt/local/lib/libopencv_ml.2.3.dylib libopencv_ml.2.3.dylib ln -s /opt/local/lib/libopencv_features2d.2.3.dylib libopencv_features2d.2.3.dylib ln -s /opt/local/lib/libopencv_highgui.2.3.dylib libopencv_highgui.2.3.dylib ln -s /opt/local/lib/libopencv_calib3d.2.3.dylib libopencv_calib3d.2.3.dylib ln -s /opt/local/lib/libopencv_objdetect.2.3.dylib libopencv_objdetect.2.3.dylib ln -s /opt/local/lib/libopencv_legacy.2.3.dylib libopencv_legacy.2.3.dylib ln -s /opt/local/lib/libopencv_contrib.2.3.dylib libopencv_contrib.2.3.dylib 
-one
source share

All Articles