Skip to content

Instantly share code, notes, and snippets.

@rickyzhang82
Forked from jruizvar/InstallOpenCV.md
Created December 7, 2017 19:35
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 rickyzhang82/034efb9b8c60f49f94560dd00668b9a7 to your computer and use it in GitHub Desktop.
Save rickyzhang82/034efb9b8c60f49f94560dd00668b9a7 to your computer and use it in GitHub Desktop.
Building OpenCV 3.2.0 from source on macOS Sierra with Python 3 support

Building OpenCV 3.2.0 from source with Python 3 support

Install OpenCV on macOS Sierra enabling Python 3 with the following instructions:

  • Install CMake, Python 3 + Numpy in advance
  • Download latest OpenCV source code (https://github.com/opencv/opencv/releases)
  • Move the folder opencv-3.2.0 to the current directory
  • In the current directory, execute the following steps:
mkdir build
cd build
cmake -DPYTHON_DEFAULT_EXECUTABLE=python3 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_opencv_python2=False -DBUILD_opencv_python3=True -DPYTHON3_EXECUTABLE=python3 ../opencv-3.2.0
make -j2
sudo make install
echo /usr/local/lib/python3.6/site-packages >> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/opencv3.pth
  • Verify installation
python3 -c "import cv2; print(cv2.__version__)"

For python2 support

cmake .. -DBUILD_opencv_python2=True -DPYTHON2_LIBRARY=$CONDA_PREFIX/lib/libpython2.7.dylib -DPYTHON2_INCLUDE_DIR=$CONDA_PREFIX/include/python2.7 -DBUILD_opencv_python3=False -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DMKL_INCLUDE_DIRS=/opt/intel/mkl/include -DMKL_ROOT_DIR=/opt/intel/mkl -DWITH_CUDA=OFF -DWITH_CUFFT=OFF -DWITH_MATLAB=OFF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment