Mac OS X EI Caption下python的opencv的安装使用

来源:互联网 发布:合并多张表sql语句 编辑:程序博客网 时间:2024/05/29 14:56

1、终端下安装brew
brew官网https://brew.sh/index_zh-cn.html有“macOS 缺失的软件包管理器”有最新的安装homebrew的命令使用。
2、brew install opencv,安装的最后有提示:

Python modules have been installed and Homebrew's site-packages is notin your Python sys.path, so you will not be able to import the modulesthis formula installed. If you plan to develop with these modules,please run:    mkdir -p /Users/chenminying/Library/Python/2.7/lib/python/site-packages    echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/mac/Library/Python/2.7/lib/python/site-packages/homebrew.pth

3、则在终端执行递归的创建目录、 在目录下创建homebrew.pth及写入内容

>>mkdir -p /Users/chenminying/Library/Python/2.7/lib/python/site-packages>>echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/mac/Library/Python/2.7/lib/python/site-packages/homebrew.pth

4、之后可以在python中执行import cv2,这里可能会提示numpy版本过低:

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

5、若import cv2提示numpy版本过低,则更新numpy的版本

>>sudo pip install --upgrade numpy

6、若更新numpy失败,提示权限不足Permission denied时,则关闭mac的SIP保护装置

 macosx 10.11 EI Capitan使用了Rootlees,可以理解为一个更高等级的内核保护,系统会默认锁定/system , /sbin , /usr这三个目录。如果没有关闭,安装一些软件时会出现:Operation not permitted,主要就是因为安装的numpy涉及到/System的问题重启电脑的同时按住command+r进入Recovery Mode恢复模式,在开始界面选择“实用工具-终端”,输入:csrutil disable关闭,这样就可以操作锁定的目录了

本文参考自https://lizonghang.github.io/2016/07/16/Mac%E4%B8%8A%E5%AE%89%E8%A3%85python-opencv/

原创粉丝点击