Mac下安装open cv for python环境

操作系统:macOS High Sierra 10.13.3

参考文章1:

http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/

参考文章2:

http://blog.csdn.net/insthink/article/details/51338839

1.先安装Xcode

输入命令:xcode-select --install

系统会安装应用Xcode,安装成功之后

2.安装Homebrew

homebrew官网点进去,复制命令:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然后安装homebrew,安装成功之后,可更新brew:brew update

3.安装opencv,输入命令:

brew install opencv

4.成功安装opencv之后,

再安装文章2的做法,进入python的site-packages目录下,并制作替身(下载好的opencv放在/usr/local/Cellar/opencv/3.4.1_2/)。

输入命令:

sudo ln -s /usr/local/Cellar/opencv/3.4.1_2/lib/python2.7/site-packages/cv.py cv.py

sudo ln -s /usr/local/Cellar/opencv/3.4.1_2/lib/python2.7/site-packages/cv2.so cv2.so

5.配置环境变量

输入命令:pico .bash_profile

添加环境变量:export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

结束之后:ctrl+X->Y->回车,保存并推出。

进入python环境,输入import cv2,即显示成功




你可能感兴趣的:(OpenCV)