Skip to content

Instantly share code, notes, and snippets.

@mcharo
Last active November 9, 2019 05:20
Show Gist options
  • Save mcharo/374add7dcb945e5a9e23329d85475e9e to your computer and use it in GitHub Desktop.
Save mcharo/374add7dcb945e5a9e23329d85475e9e to your computer and use it in GitHub Desktop.
Installing OpenCV 4.1.2 on macOS Mojave
#!/bin/bash
# references:
# - https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a
# - https://www.learnopencv.com/install-opencv3-on-macos/
# - https://bob.ippoli.to/archives/2005/02/06/using-pth-files-for-python-development/
# this is probably /usr/local for you
BREW_ROOT="/usr/local/homebrew"
# create virtualenv called venv
python -m venv venv
source ./venv/bin/activate
# install opencv python prereqs and probably some extras
pip install numpy scipy matplotlib scikit-image scikit-learn ipython pandas
# exit venv
deactivate
# install opencv
brew install opencv
# much much later, add opencv python packages to homebrew python install
echo $BREW_ROOT/opt/opencv/lib/python3.7/site-packages >> $BREW_ROOT/lib/python3.7/site-packages/opencv3.pth
# link opencv library into venv (or maybe any python install you prefer)
cd venv/lib/python3.7/site-packages
ln -s $BREW_ROOT/opt/opencv@4/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-darwin.so cv2.so
# enter venv and test opencv
source ./venv/bin/activate
python -c "import cv2; print(cv2.__version__)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment