更新mac自带的python版本至python3

原地址&感谢:https://my.oschina.net/u/2255341/blog/1794831
摘要: 今年Mac os用户必须要更新,系统自带的python版本了。因为pypi将停止对TLS 1.0和1.1的支持, MacOS附带的系统Python在任何MacOS版本中都不支持TLSv1.2。

今天在虚拟环境中使用pip 安装pylint的时候发现出现了TLS版本过低问题。

(py3env) ☁  py3env  pip install pylint 
Collecting pylint
  Could not fetch URL https://pypi.python.org/simple/pylint/: 
There was a problem confirming the ssl certificate: 
[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:720) - skipping
  Could not find a version that satisfies the requirement pylint (from versions: )
No matching distribution found for pylint

然后想起了去年有一篇文章说python.org和pypi将停止对TLS 1.0和1.1的支持,然后又找到了这篇文章

http://pyfound.blogspot.in/2017/01/time-to-upgrade-your-python-tls-v12.html 

文章中明确说明

Mac users should pay special attention. So far, the system Python shipped with MacOS does not yet support TLSv1.2 in any MacOS version; beginning next June these system Pythons will no longer be able to "pip install" packages.

Mac用户应该特别注意,到目前为止,MacOS附带的系统Python在任何MacOS版本中都不支持TLSv1.2。所以是时候升级一下python3的版本了,而且可以体验一下python 3.6的异步解析式和生成器。

记录一下升级到os X升级到python3.6的过程。

1、有必要先切换一下Homebrew的源,中科大镜像源

替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

2、更新python3,直接安装就会自动更新。

brew install python3

更新过程中会遇到一个问题:

Error: The `brew link` step did not complete successfully

Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

遇到这个权限问题的时候执行下面,

sudo mkdir -p /usr/local/Frameworks

sudo chown -R $(whoami) /usr/local/* 

然后在执行

brew link python3

可能会遇到之后这个问题:

Linking /usr/local/Cellar/python3/3.6.4_1... 

Error: Could not symlink bin/idle3

Target /usr/local/bin/idle3

already exists. You may want to remove it:

  rm '/usr/local/bin/idle3'

To force the link and overwrite all conflicting files:

  brew link --overwrite python3

To list all files that would be deleted:

  brew link --overwrite --dry-run python3

就更具提示把该删除的删除一下就好了 

rm /usr/local/bin/idle3
rm /usr/local/bin/pydoc3

在执行
brew link --overwrite python3

这样就安装成功了。

 

参考链接:

brew源更新: https://www.zhihu.com/question/31360766

低版本TLS停止支持公告 : http://pyfound.blogspot.in/2017/01/time-to-upgrade-your-python-tls-v12.html

brew安装python3 issue : https://github.com/Homebrew/homebrew-core/issues/20985


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值