macbook上多版本python切换

macbook上默认安装了2.x版本的python,如果有时候要使用2.x版本的python,有时候想使用2.x版本的python,怎么办?

  • 已经有了2.x的python,此时再安装3.x的python:

$ brew install python

如果没有报错,则该步骤完成,如果报一个警告Warning: python3-3.x.y already installed, it’s just not linked
解决方法:
$ sudo ln -s /usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/bin/python3
/usr/local/bin/python3*

  • 使用python2.x时,在终端输入 python,要使用python3时在终端输入python3即可。

$ python Python 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1
Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin Type “help”,
“copyright”, “credits” or “license” for more information.

$ python3
Python 3.5.1 (default, Apr 18 2016, 11:46:32) [GCC 4.2.1
Compatible Apple LLVM 7.3.0 (clang-703.0.29)] on darwin Type “help”,
“copyright”, “credits” or “license” for more information. $

如果要在文件中指定使用python2或者python3,则只需要在首行写上#/usr/bin/env python 或者/usr/bin/env python3即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值