Took me a while to figure this out so I thought I'd write it down.
Install python with shared library support through pyenv:
env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.5.0
Make a new virtualenv named opencv
pyenv virtualenv 3.5.0 opencv
Activate the virtualenv and install numpy
pyenv activate opencv
pyenv rehash
pip install numpy
Clone opencv and opencv_contrib and put it in ~/
cd ~
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 3.1.0
cd ~
git clone https://github.com/Itseez/opencv_contrib
cd opencv_contrib
git checkout 3.1.0
cd ~/opencv
mkdir build
cd build
Run CMake and install
PREFIX_MAIN=`pyenv virtualenv-prefix`
PREFIX=`pyenv prefix`
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX="$PREFIX" \
-D PYTHON3_EXECUTABLE="$PREFIX"/bin/python3.5 \
-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=~/opencv_contrib/modules ..
make -j8
make install
Note: if you are using python 3.5.2 you need to change
PYTHON3_EXECUTABLE="$PREFIX"/bin/python3
PYTHON3_LIBRARY="$PREFIX_MAIN"/lib/libpython3.5m.a
source: basically mashed these guides together:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With