Step1.查看系统当前python版本号,命令行输入 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.
>>>
Step2.下载最新版本:
https://www.python.org/downloads/
截止目前最新版本为: 3.6.2
Step3.选择同时存在python多个版本,还是最新版本:
如果想存在多个版本,直接跳到4,如果想只存在最新版本,由于python是在/System目录下,要删除的话必须关闭rootless机制,原理和修改的链接地址为:
http://blog.csdn.net/zqm201/article/details/49070751
Step4.安装python3.6.2
安装pkg之后,会默认写入
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
到你的 ~/.bash_profile文件中。
然后自己在后面加入以下文本:
alias python="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6"
退出后生效: source ~/.bash_profile
Step5.执行python
此时执行python即可看到最新版本:
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
然后输入一句永不变的话:
>>> print("Hello Chenzhe!")
Hello Chenzhe!
>>>
PS:安装pip:
直接调用brew安装:
brew install pip
会提示一下大致错误:
Homebrew provides pip via: `brew install python`. However you willthenhavetwoPythons installedonyourMac,soalternativelyyoucaninstallpip viatheinstructionsat:
在brew中,pip的安装是跟python一起的。所以正确安装方法:
sudo easy_install pip