Skip to content

Instantly share code, notes, and snippets.

@tkdave
Created November 26, 2012 21:58
Show Gist options
  • Save tkdave/4150916 to your computer and use it in GitHub Desktop.
Save tkdave/4150916 to your computer and use it in GitHub Desktop.
Installing OpenCV python libs on mac to work with virtualenv and brew
# Installing OpenCV python libs on mac to work with virtualenv
# OpenCV 2.4.3
# Python 2.7.3 installed with brew
# assuming you have virtualenv, pip, and python installed via brew
# assuming $WORKON_HOME is set to something like ~/.virtualenvs
# using homebrew - make sure we're current
brew update
# setup virtual env
mkvirtualenv opencv
workon opencv
# install numpy
pip install numpy
# requirements for opencv
brew install lame jpeg png cmake pkg-config eigen libtiff jasper ffmpeg
brew link jpeg lib png
# XX SHA1 mismatch on tbb
mate /usr/local/Library/Formula/tbb.rb
#Update Lines 5 and 6 to latest source and sha1
url 'http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20121112oss_src.tgz'
sha1 '752943b78d7a6d3a764feb1bbd7df6c230170cf1'
brew install tbb
# download OpenCV
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.3/OpenCV-2.4.3.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fopencvlibrary%2Ffiles%2Fopencv-unix%2F2.4.3%2F&ts=1353964941&use_mirror=iweb
# unzip
tar xvfJ OpenCV-2.4.3.tar.bz2
cd OpenCV-2.4.3/
mkdir release
cd release
cmake -D PYTHON_EXECUTABLE=$WORKON_HOME/opencv/bin/python \
-D PYTHON_PACKAGES_PATH=$WORKON_HOME/opencv/lib/python2.7/site-packages \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D PYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Headers \
-D PYTHON_LIBRARY=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib \
..
make -j8
make install
@yassersouri
Copy link

what should change if I have the default python installed on macs?

@tomatohater
Copy link

Belated but...

@yassersouri You would then leverage the default include and lib directories (i.e. remove the "-D PYTHON_INCLUDE_DIR" and "-D PYTHON_LIBRARY" options.)

If you're not using a virtualenv, then you can remove the other two PYTHON related options, but I'm not sure why anyone would want to so that! :)

Here's the command I run (with a virtualenv, but default Python headers libs):

cmake -D PYTHON_EXECUTABLE=$WORKON_HOME/opencv/bin/python \
-D PYTHON_PACKAGES_PATH=$WORKON_HOME/opencv/lib/python2.7/site-packages \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_PYTHON_SUPPORT=ON \
..

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