Mac使用brew安装Python3.*并设为默认版本

Posted liuhmmjj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac使用brew安装Python3.*并设为默认版本相关的知识,希望对你有一定的参考价值。

mac系统虽然默认打开的是python2,但是也默认自带了python3,只要在终端用命令

python3

就会打开python3

下面讲的是用brew安装最新的python3

brew install python3

可以看到python3的实际安装目录是/usr/local/Cellar/python@3.9/3.9.12

打开配置文件并写入python的外部环境变量

open ~/.bash_profile
然后写入:
export PATH=$PATH:/usr/local/Cellar/python@3.9/3.9.12/bin
alias python="/usr/local/Cellar/python@3.9/3.9.12/bin/python3.9"

最后让文件生效:

source ~/.bash_profile

使用python命令查看

python -V
显示为:
Python 3.9.12

以上是关于Mac使用brew安装Python3.*并设为默认版本的主要内容,如果未能解决你的问题,请参考以下文章