【OpenCV】 macOS Sierra下Python3.6配置

Suppose you have completed the installation of Homebrew and Python3.6.

Step 1. Download OpenCV using brew

brew install opencv

cd /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
echo /usr/local/opt/opencv@3/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so
ln -s /usr/local/opt/opencv@3/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so cv2.so

Step3: Error handling

Enter Python3.6, input “import cv2”, you might get

>>> import cv2
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import

Then, what you should do is merely update the numpy to the latest version, like type following in the terminal:

pip3.6 install -U numpy

Others:
If you want to install OpenCV2 instead of OpenCV3, you can use

brew search opencv

to find any version provided by brew. Here I have opencv (which denotes 3) and opencv@2. Currently (2018.01.09), OpenCV2 merely supports python2 while OpenCV3 offers .so to both of 2 and 3.
If you want to install caffe and using OpenCV2, then if you use brew to install both of OpenCV2 and 3, you may need the following instruction

brew link opencv@2

to allow cmake find right opencv when make the file.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值