Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
November 2016 installation of opencv3 from source into pyenv virtualenv python3.5.2 environment

Installing openCV3 into pyenv virtual env

osx 10.11.6


  • install python-3:
$ pyenv install 3.5.2
  • make a new virtualenv
$ pyenv virtualenv 3.5.2 cv
  • activate the virtualenv and install numpy
$ pyenv activate cv
(cv)$ pyenv rehash
(cv)$ pip install numpy
  • clone opencv and opencv_contrib
(cv)$ cd ~/src/openCV/Oct2016
(cv)$ git clone
(cv)$ git clone
  • prefer to build outside of opencv repository
(cv)$ mkdir build_vpy3
(cv)$ cd build_vpy3
  • the folder structure:
  • CUDA-8 doesn't compile with xcode-8 so change default:
$ sudo xcode-select -switch /Applications/

I had previously manually downloaded the older version of xcode from Apple and renamed the destination from to so that the latest version won't overwrite it.

  • Ensure virtual environment is still active
~/src/openCV/October2016/build_vpy3:$ pyenv activate cv
  • run cmake, make, and make install
(cv)$ PREFIX_MAIN=pyenv virtualenv-prefix
(cv)$ PREFIX=pyenv prefix
    -D PYTHON3_EXECUTABLE="$PREFIX"/bin/python3 \
    -D PYTHON3_PACKAGES_PATH="$PREFIX"/lib/python3.5/site-packages \
    -D PYTHON3_LIBRARY="$PREFIX_MAIN"/lib/libpython3.5m.dylib \
    -D PYTHON3_INCLUDE_DIR="$PREFIX_MAIN"/include/python3.5m \
    -D PYTHON3_NUMPY_INCLUDE_DIRS="$PREFIX"/lib/python3.5/site-packages/numpy/core/include \
    -D BUILD_opencv_python3=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/src/source/openCV/Oct2016/opencv_contrib/modules ../opencv/
(cv)$ make -j4
(cv)$ make install


snippets and notes

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