升级Mac自带Python版本
最近捡起荒废已久的Python从头开始学,在安装pyinstaller
时发现Mac自带的2.7版本将于2020年停止支持,于是决定升级一下。
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
第一步:下载Python最新版本
官网下载地址:https://www.python.org/downloads/,我下的时候最新版为3.7.3
第二步:安装
点击下载好的pkg文件进行安装
第三步:修改Mac自带的python路径
安装后在终端中输入:python -V
,发现默认仍然使用2.7版。在网上查询了下,很多人通过修改根目录下的.bash_profile
文件来改变Mac默认的Python路径。我找了半天发现没有这个文件,有两个解决办法:一个是自己新建一个 .bash_profile
文件并输入相应代码,另一个是进入/Applications/Python 3.7
路径,双击Update Shell Profile.command
文件就能在根目录下生成.bash_profile
文件。
打开.bash_profile
文件:
open ~/.bash_profile
在其中最后一行加入:
alias python="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7"
.bash_profile
文件最终代码如下:
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
alias python="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7"
重启一下终端,再用python -V
验证一下就可以了。
嗯,时隔一年多,居然更新了,居然还是博客3周年。争取今年把2018年落下的补上,我这是有多懒😄️。