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即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章