# OpenCV3 with Python3.5 on Mac OS X Yosemite ## Installation of the dependencies * First install the python3 using homebrew ```bash $ uname -a Darwin apple 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64 $ brew install python3 $ brew linkapps $ brew install cmake pkg-config $ brew install jpeg libpng libtiff openexr $ brew install eigen tbb ``` ### Set the Path Variables ```sh export PATH=/usr/local/bin:$PATH export PYTHONPATH=/usr/local/lib/python3.5/site-packages ``` ### Check the Python 3 version and path ```sh $ which python3 /usr/local/bin/python3 ``` ### Install the NumPy Package using the Python package manager ```sh $ pip3 install numpy ``` ### Check the python system variables ```python $ python3 -m sysconfig $ python3 >>> import numpy as np >>> np.get_include() '/usr/local/lib/python3.5/site-packages/numpy/core/include' ``` ### Clone the opencv and opencv_contrib packages from github ```sh $ git clone https://github.com/Itseez/opencv.git $ cd opencv $ git checkout 3.1.0 $ git clone https://github.com/Itseez/opencv_contrib $ cd opencv_contrib $ git checkout 3.1.0 ``` ### Create the build directory ```sh $ cd opencv $ mkdir build $ cd build ``` ### Using cmake to configure * Adjust the Python3 Paths and set INSTALL_C_EXAMPLES=OFF ```bash $ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D PYTHON3_EXECUTABLE=/usr/local/bin/python3 \ -D PYTHON3_PACKAGES_PATH=/usr/local/lib/python3.5/site-packages \ -D PYTHON3_LIBRARY=/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5m.dylib \ -D PYTHON3_INCLUDE_DIR=/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/include/python3.5m \ -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/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 OPENCV_EXTRA_MODULES_PATH=/opt/software/opencv_contrib/modules .. ``` #### If there are no errors, run the make ```bash $ make -j4 ``` #### Install the library ```bash $ make install ``` #### Check the OpenCV Python shared object ```bash > ll /usr/local/lib/python3.5/site-packages/cv2* -rwxr-xr-x /usr/local/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so > ll lib/python3/ -rwxr-xr-x cv2.cpython-35m-darwin.so # Check the version $ python3 Python 3.5.1 (default, Feb 21 2016, 11:54:27) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> cv2.__version__ '3.1.0' ```