mac安装python3,与python2共存

今天需要用到python3,想起以前电脑上安装过两个版本的python,结果python3莫名其妙的不能用了,百思不得其解,想了下,可能是前不久更新了brew,这个mac软件安装神器,对于python的规则有所改动,毕竟python3现在是主推的。

按照原来印象中的办法,使用brew安装python3

brew install python3
提示我如下信息:

➜  ~ brew install python3
Error: python 2.7.14 is already installed
To upgrade to 3.7.0, run `brew upgrade python`

python2.7.10是mac系统默认自带的,猛一看让我更新python版本,害怕把python2给覆盖掉,这可就坑大了,在google上搜了一下这个问题,果然是brew的更新导致的,传送门https://brew.sh/2018/01/19/homebrew-1.5.0/

在stackoverflow找到了遇到同样问题的小伙伴,最下面有个小伙子勇往直前,按照提示执行了 brew upgrade python,然后实践证明了,并不会覆盖自己本地的python2,好吧,赌一把,更新了,成功安装了python3.7.0

➜  ~ brew upgrade python
==> Upgrading 1 outdated package, with result:
python 2.7.14 -> 3.7.0

等待更新完成之后,赶快验证了一下,没毛病

➜  ~ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

➜  ~ python3
Python 3.7.0 (default, Jun 29 2018, 20:14:27)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()

可以开心的使用虚拟环境来创建python3的开发环境沙盒了,美滋滋。

➜  ~ mkvirtualenv -p python3 venv-myprojet
Running virtualenv with interpreter /usr/local/bin/python3

附上答案地址:stackflow问题地址

你可能感兴趣的:(mac安装python3,与python2共存)