Skip to content

Instantly share code, notes, and snippets.

@larsyencken
Last active August 29, 2015 13:58
Show Gist options
  • Save larsyencken/9969942 to your computer and use it in GitHub Desktop.
Save larsyencken/9969942 to your computer and use it in GitHub Desktop.
Building opencv on OS X 10.9 Mavericks

Here's my saga. It's heavily based on this earlier gist, but adapted for Mavericks. I'm starting off from pyenv running anaconda-1.9.1.

I tried several versions, but only 2.4.8 compiled successfully for me.

wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.8/opencv-2.4.8.zip
unzip opencv-2.4.8.zip
cd opencv-2.4.8

Let's build it! You'll need cmake, pretty sure I got this from brew install cmake.

mkdir release
cd release
cmake \
  -DPYTHON_INCLUDE_DIR=$HOME/.pyenv/versions/anaconda-1.9.1/include/python2.7 \
  -DPYTHON_LIBRARY=$HOME.pyenv/versions/anaconda-1.9.1/lib/libpython2.7.dylib \
  -DPYTHON_EXECUTABLE=$HOME/.pyenv/versions/anaconda-1.9.1/bin/python \
  -DPYTHON_PACKAGES_PATH=$HOME/.pyenv/versions/anaconda-1.9.1/lib/python2.7/site-packages \
  ..

If it all builds successfully, you can now run make install.

I also had to manually fix the python module in order to work:

sudo install_name_tool -change libpython2.7.dylib ~/.pyenv/versions/anaconda-1.9.1/lib/libpython2.7.dylib ~/.pyenv/versions/anaconda-1.9.1/lib/python2.7/site-packages/cv2.so

At the end of all of this, you should be able to run

$ python
>>> import cv2

without a segfault.

@porty
Copy link

porty commented Apr 5, 2014

+1 for not cheating and using Vagrant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment