Install OpenCV for Python (multiple python versions)

Use virtualenv

virtualenv -p python2.7 env
source env/bin/activate
python --version  # prints «Python 2.7.3»
pip install pyopencv

If you need support of 2.4 (or other version), just create new environment.


There are some Cmake flags which allow you to explicitly specify which version of Python to use. You will need to set the values of these flags to the correct location for your installation of Python.

The flag names and likely locations are below:

PYTHON_EXECUTABLE=/usr/bin/python2.7/
PYTHON_INCLUDE=/usr/include/python2.7/
PYTHON_LIBRARY=/usr/lib/libpython2.7.a    //or .so for shared library
PYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/
PYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/dist-packages/numpy/core/include

If these paths don't work, you will need to locate them on your machine.