1. 使用Homebrew
安装
brew install python3 # 必须要安装,尤其要做好 brew link python3
brew install opencv
最新版本的opencv
已经不分opencv3
了,而是在目录下分成python2
和python3
版本的文件夹。
安装好的opencv
库在/usr/local/Cellar/opencv/
。
不同版本分别在
# python3
opencv/3.4.1_5/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so
# python2
opencv/3.4.1_5/lib/python2.7/site-packages/cv2.so
2. 进入python 的site-packages 目录下制作替身
cd 到Python的site-packages中
ln -s 目标文件 文件名称
# 例如:
cd my_tf/lib/python3.5/site-packages
ln -s /usr/local/Cellar/opencv3/3.1.0_4/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so cv2.so
3. 依赖包
这时候试试看是否成功
Python 3.5.3 |Anaconda custom (x86_64)| (default, Mar 6 2017, 12:15:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
升级响应的依赖包
pip install --upgrade numpy
成功
Python 3.5.3 |Anaconda custom (x86_64)| (default, Mar 6 2017, 12:15:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
网友评论