Skip to content

Instantly share code, notes, and snippets.

Embed
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 https://github.com/Itseez/opencv.git
(cv)$ git clone https://github.com/Itseez/opencv_contrib
  • prefer to build outside of opencv repository
(cv)$ mkdir build_vpy3
(cv)$ cd build_vpy3
  • the folder structure:
~/src/openCV/Oct2016/opencv/
                    /opencv_contrib/
                    /build_vpy3/
  • CUDA-8 doesn't compile with xcode-8 so change default:
$ sudo xcode-select -switch /Applications/Xcode-7.3.app

I had previously manually downloaded the older version of xcode from Apple and renamed the destination from Xcode.app to Xcode-7.3.app 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
(cv)$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX="$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 INSTALL_C_EXAMPLES=OFF \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON \
    -D BUILD_opencv_python3=ON \
    -D INSTALL_NAME_DIR=${CMAKE_INSTALL_PREFIX}/lib \
    -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