OpenCV + Python 2.6 (on OS X)

So, I was trying to get OpenCV and NumPy to work together on my Mac (10.6). Problem was, NumPy wanted to live on Python 2.6, and OpenCV wanted to live on Python 2.7. Much misery was had.

Solution I found (finally!) was:

  1. Install NumPy. (I can’t quite remember how to do this. Just do what the instructions say.)
  2. Install OpenCV. Per the instructions, the steps are as follows:
    cd ~/<my_working_directory>
    svn co
    cd ~/<my_working_directory>/trunk/opencv # directory should contain INSTALL, CMakeLists.txt etc.
    mkdir release
    cd release
    sudo make install

    Note the BUILD_PYTHON_SUPPORT and PYTHON_EXECUTABLE flags to cmake. In the output to cmake, you should see:

    Python: ON
    Python interpreter: /usr/bin/python2.6
    Python numpy: YES

    under “Interfaces:”.

  3. Test the install. Launch Python, and run:
    import numpy
    import cv

    Nothing bad should happen!

(Make sure the “release” directory is nice and clean before you run cmake & make. At one point, my release directory was in some weird state so that after I ran make, “import cv” gave me a segfault. Clearing out the directory and rerunning the install process made everything work!)