Last Updated: February 25, 2016
·
3.718K
· tttthomasssss

Setting up openCV with Python virtualenvs

The hardest part in using openCV is installing it - especially if you want to use it within a Python virtualenv. Its been a while since I had to swear that much during an installation...

I found that the best way (in fact, for me it was the only way) to actually get openCV to work with a virtualenv is to install it from source:

> cd /path/to/some/folder
> git clone https://github.com/Itseez/opencv.git
> cd opencv
> mkdir release
> cd release
> cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DPYTHON_EXECUTABLE=~/.virtualenvs/<my_virtualenv>/bin/python2.7 ..
> make
> sudo make install

If you don't have cmake installed, you can easily get it from homebrew (brew install cmake) or macports. Note that the cmake above assumes that your virtualenv base dir is ~/.virtualenvs.

If all that stuff finished successfully, you finally should be able to use openCV from your virtualenv.