本文地址:http://www.cnblogs.com/QingHuan/p/7354074.html

转载请注明本文地址,方便读者查看本文更新,谢谢!

今天要在Mac上安装OpenCV,过程非常曲折,充分体会到了每个人的安装过程都是不同的

具体参考了以下几篇博客:

[1] http://www.jianshu.com/p/6e345b3aa988

[2] http://www.jianshu.com/p/b5424e9cb7ad

[3] http://blog.csdn.net/willduan1/article/details/53898440

[4] http://nooverfit.com/wp/手把手教你,在ubuntu上安装opencv-3-0-和-python-2-7/

在参考 [1] 的过程中,还下载了Anaconda,其实最后都没有用上

另外推荐一本学习Python的书:

https://www.gitbook.com/book/lenkimo/byte-of-python-chinese-edition/details

下面是正式安装过程,目的是使用PyCharm进行Python开发

// 更新:可以不安装虚拟环境,直接跳到第二节,选择系统默认的python2.7即可

// 再更新,其实可以在Pycharm里配置安装虚拟环境(实在太赞了),如下图

第一节 安装虚拟环境

参考 [2] 和 [4] ,感谢原作者!

安装virtualenv和virtualenvwrapper. 用来分割python虚拟环境. 这不是必须的, 但是强烈推荐:

$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip

如果报以下的错误:

Operation not permitted: '/tmp/pip-bxaFhj-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

参考[7] https://github.com/pypa/pip/issues/3165

输入

sudo pip install virtualenv virtualenvwrapper --upgrade --ignore-installed six

即可

原因是:

This is because OS X El Capitan ships with six 1.4.1 installed already and when it attempts to uninstall it (because awscli depends on botocore, botocore depends on python-dateutil, and python-dateutil depends on six >= 1.5) it doesn't have permission to do so because System Integrity Protection doesn't allow even root to modify those directories.

Ideally, pip should just skip uninstalling those items since they aren't installed to site-packages they are installed to a special Apple directory. However, even if pip skips uninstalling those items and installs six into site-packages we'll hit another bug where Apple puts their pre-installed stuff earlier in the sys.path than site-packages. I've talked to Apple about this and I'm not sure if they're going to do anything about it or not.

也就是six的版本问题

现在我们有了virtualenv和virtualenvwrapper, 我们要更新我们的~/.bashrc  文件:(Mac中为.bash_profile)(修改原因参考 [5] )

在Mac中:
vi ~/.bash_profile 如果提示Read-only file,不允许写入的话,执行:
chmod a+w ~/.bash_profile 如果在Linux系统中:
vi ~/.bashrc

然后将下面的几行复制到最末尾

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

为了使~/.bashrc 文件生效 , 你可以用以下这些方法的其中之一(1) 注销后重新登录, (2)关闭终端开一个新终端, (3)直接使得~/.bashrc文件在当前生效,执行:

$ source ~/.bashrc

最后我们生成虚拟开发环境:

$ mkvirtualenv python2.7forOpencvExp

1.1 安装Python

安装python包管理器pip:

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py

安装Python-2.7.13:

brew install python

安装好后的python路径为 /usr/local/Cellar/python/2.7.13_1

可执行文件的位置在  /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/bin/python2.7

可以参考 [6] 来修改虚拟环境使用的python版本,

你可以选择使用一个Python解释器(比如``python2.7``):

$ virtualenv -p /usr/bin/python2.7 my_project

如果想查看全局的python位置,输入

whereis python

第二节 在PYCHARM中进行配置:

1. 点击左上角的Pycharm Edu ==> Preferences ==> Project Interpreter,如图

选择解释器为虚拟环境中安装的那个(图中没选对,下面也是,当时安装的是python3.6但是发现不好用)。

2. 点击左下角的“+”加号,进入PYTHON的包管理界面

搜索Opencv,选中opencv-python,点击Install Package;同理再安装opencv-contrib

3. 完成最后的配置,还是在Preferences内,选择Build, Execution, Deployment ==> Console ==> Python Console,

选择Python Interpreter为虚拟环境中安装的那款,如图

然后点击OK进行确定

4. 测试:在文本框内输入如下命令:

import cv2
print(cv2.__version__)

运行后得到当前Opencv版本为3.3.0,如图

至此就安装好了!

--- THE END ---

参考文献:

[1] http://www.jianshu.com/p/6e345b3aa988

[2] http://www.jianshu.com/p/b5424e9cb7ad

[3] http://blog.csdn.net/willduan1/article/details/53898440

[4] http://nooverfit.com/wp/手把手教你,在ubuntu上安装opencv-3-0-和-python-2-7/

[5] http://elf8848.iteye.com/blog/1582137

[6] http://pythonguidecn.readthedocs.io/zh/latest/dev/virtualenvs.html

[7] https://github.com/pypa/pip/issues/3165

Mac + PyCharm 安装 Opencv3 + python2.7的更多相关文章

  1. Mac下安装OpenCV3.0和Anaconda和环境变量设置

    入手Mac几天了,想在Mac OS下玩玩OpenCV和keras,间歇捣鼓了两天,终于搞定zsh.OpenCV3.0以及Anaconda.OpenCV3.0刚发布不久,这方面的资料也不是很多,能够查到 ...

  2. mac上安装opencv3

    转载于:http://blog.csdn.net/sanwandoujiang/article/details/51159983 在macosx上安装opencv2 brew tap homebrew ...

  3. Mac下安装配置Python2和Python3并相互切换使用 转

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u014259820/article/details/81023224 安装Python2 Mac系统 ...

  4. Mac下安装配置Python2和Python3并相互切换使用

    mac os 以前没有使用过,这次使用了一把,的确还是比较不顺手的,估计从今以后,就要把平台逐渐切换到mac了.今后好的文章,专门会开一个macos专栏,专门记录macos的使用过程中的心得,体会,以 ...

  5. mac10.12.6系统使用cmake安装opencv3.3.0+opencv_contrib-3.3.0

    brew与cmake brew安装 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/ins ...

  6. Mac同时安装python2和python3

    Mac同时安装python2和python3 Mac自带python2,但因为开发时所用但pythonkennel是3也可能是2,并且就算是python2,版本号也许和内置但python也有所不同.所 ...

  7. Mac OS X10.9安装的Python2.7升级Python3.4步骤详解

    Mac OS X10.9安装的Python2.7升级Python3.4步骤详解 Mac OS X10.9默认带了Python2.7,不过现在Python3.4.0出来了,如果想使用最新版本,赶紧升级下 ...

  8. Python2和Python3的安装以及pycharm安装,path环境变量的配置

    一:安装python2.7过程步骤 1.官网下载pythonan安装包: ·输入python搜索 ·找到python官网,点击进入 ·鼠标放在Downloads上,在新弹出的选项中选择Windows, ...

  9. mac os 安装PIP 及异常“”Can't install python module: PyCharm Error: “byte-compiling is disabled, skipping”“”的解决方案

    For all who have the same problem, it took me a while to find the solution in a new installation of ...

随机推荐

  1. Docker Swarm 创建服务

    Docker Swarm 创建服务 环境: 系统:Centos 7.4 x64 应用版本:Docker 18.09.0 管理节点:192.168.1.79 工作节点:192.168.1.78 工作节点 ...

  2. 在线视频下载利器——youtube-dl

    youtube-dl是谷歌出品的在线视频下载利器,可以用来下载youtube视频(前提是你得能上youtube). 使用方法很简单,只需要在cmd下执行youtube-de.exe +视频页面网址,程 ...

  3. 使用curl自动签到百度贴吧

    百度贴吧的一键签到接口地址为 http://tieba.baidu.com/tbmall/onekeySignin1 curl http://tieba.baidu.com/tbmall/onekey ...

  4. vue中使用cookies和crypto-js实现记住密码和加密

    前端加密 使用crypto-js加解密 第一步,安装 npm install crypto-js 第二步,在你需要的vue组件内import import CryptoJS from "cr ...

  5. SpringBootsad整合EhCache做缓存处理

    轻量级的缓存框架Ehcache实现其功能.从以下几点切入: 什么是EhCache? 它和redis.membercache比较有什么优势? 和SpringBoot怎么整合? 实现机制? 有哪些坑? E ...

  6. 《温故而知新》JAVA基础四

    类的封装 定义:将类的一些信息隐藏起来,不允许外部的程序直接的访问,而是通过该类提供的一些方法来获取 好处:只能通过特定的法方法访问数据,保护了数据, 实现封装的步骤: 修改属性的可见性:(一般类属性 ...

  7. ios外派公司—提供ios程序员外派ios应用外包业务(北京动点 可签合同)

    北京动点飞扬长年提供ios工程师外派业务. 我公司程序员平均技术情况如下: 1.二年以上iPhone/ipad开发经验: 2.熟练使用Xcode.Objective C编码技能: 3.熟悉iOS开发框 ...

  8. 5种网络IO模型(有图,很清楚)

    同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问题其实不同的人给出 ...

  9. Mysql5.7出现this is incompatible with sql_mode=only_full_group_by

    vi /etc/my.cnf #编辑mysql配置文件 在 [mysqld]和[mysql]下添加 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZE ...

  10. Bean的Scope

    Bean的scope: 1.Singleton(单例): 一个Spring容器只有以这个Bean实例. 2.prototype(多例): 每次调用新建一个Bean的实例. 3.request:一个ht ...