Skip to content

Instantly share code, notes, and snippets.

@corenel
Last active January 18, 2018 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corenel/19a64216897550a5721c2213534cfbd9 to your computer and use it in GitHub Desktop.
Save corenel/19a64216897550a5721c2213534cfbd9 to your computer and use it in GitHub Desktop.
Installation of OpenCV 3 in virtualenv on Ubuntu 16.04
  1. download OpenCV 3.3.1 and unzip.
# download opencv 3.3.1
# https://codeload.github.com/opencv/opencv/zip/3.3.1
unzip opencv-3.3.1.zip
cd opencv-3.3.1
mkdir build
cd build
  1. configure and build
# specify CUDA_ARCH_BIN to speed up building
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV/usr/local -D PYTHON3_EXECUTABLE=$VIRTUAL_ENV/bin/python -D BUILD_opencv_python3=ON -DCUDA_ARCH_BIN="6.1" ..

make -j7
make install

if you just want to install in /usr/local instead if virtual environment, run the following command:

cmake -D CMAKE_BUILD_TYPE=Release -D PYTHON3_EXECUTABLE=$(which python3) -D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")  -D PYTHON3_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DPYTHON_DEFAULT_EXECUTABLE=$(which python3) -D BUILD_opencv_python3=ON -DCUDA_ARCH_BIN="6.1" ..
  1. add path
# take care of python version
# add this to your bash/zsh profile
export PYTHONPATH="$VIRTUAL_ENV/usr/local/lib/python3.6/site-packages:$PYTHONPATH"
export PKG_CONFIG_PATH="$VIRTUAL_ENV/usr/local/lib/pkgconfig/"
export LD_LIBRARY_PATH="$VIRTUAL_ENV/usr/local/lib/:$LD_LIBRARY_PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment