2022年 11月 4日

mac 升级自带Python方法

网上查的很多都是使用命令

  open ~/.bash_profile

实际上并没有这个文件。(如果可以顺利打开,请跳过这一步)

需要已经在Download Python | Python.org 下载pkg包,并且安装到默认路径

需要自己手动创建一个,命令如下

  1. cd ~
  2. touch ~/.bash_profile
  3. open ~/.bash_profile

然后在文本输入中编辑文件,文件内容为

export PATH=”/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}”
alias python=”/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10″

执行命令

  source ~/.bash_profile

验证版本

终端输入python,可以看到mac自带python版本已经是我们修改的版本

如果每次打开终端都会重新回到自带Python的版本,需要修改到zshrc文件

  1. cd ~
  2. ls -a
  3. vi zshrc

在zshrc中加入

source ~/.bash_profile

如果想回到mac自带的python版本,只需要像上面那样打开~/.bash_profile,然后注释掉最后的alias