Installing OpenCV3 for python3 with homebrew. numpy should be installed before!

You can find lots of articles about how to install OpenCV3 for python3 with homebrew.
If it doesn't create python bindings for python3, it is because you don't have numpy on your python3 environment.

CAUTION: you MUST NOT use pyenv or virtualenv generated python environment while installing a package with homebrew. refer http://docs.brew.sh/Homebrew-and-Python.html (

Virtualenv

WARNING: When you brew install formulae that provide Python bindings, you should not be in an active virtual environment.
Activate the virtualenv after you’ve brewed, or brew in a fresh Terminal window. Homebrew will still install Python modules into Homebrew’s site-packages and not into the virtual environment’s site-package.
Virtualenv has a switch to allow “global” (i.e. Homebrew’s) site-packagesto be accessible from within the virtualenv.)

Install numpy on your python3 environment before.(Do not use pyenv or virtualenv, install it on the system python3 directly)

$ brew install numpy --without-python --with-python3 
$ brew install opencv3 --with-python3 --without-python
$ echo /usr/local/Cellar/opencv3/3.2.0/lib/python3.6/site-packages >> /usr/local/lib/python3.6/site-packages/opencv3.pth # replace python3.6 to your python path and version properly



then it will create
/usr/local/Cellar/opencv3/3.2.0/lib/python{YOUR_PYTHON_VERSION}/site-packages/cv2.cpython-{YOUR_PYTHON_VERSION}m-darwin.so



The way I figured out the problem is 
$ brew install opencv3 --with-python3 --without-python --verbose

With the --verbose option, it told me that numpy is not found. :)
hope this helps you not dig anymore.

# check opencv2 with python3 binding works
$ python3 -c "import cv2; print(cv2.__version__);"


댓글