用homebrew 升级安装python3.7 之后系统的python版本还是旧的怎么办

时间:2023-03-09 00:39:55
用homebrew 升级安装python3.7 之后系统的python版本还是旧的怎么办

mac 中安装了多个版本的python$ brew install python3

Updating Homebrew...
Warning: python 3.7. is already installed, it's just not linked
You can use `brew link python` to link this version.
#brew 提示已经安装了 3.7.
但是系统变量里检测不到 并提示用 `brew link python` 来链接
$ brew link python
Linking /usr/local/Cellar/python/3.7....
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
rm '/usr/local/bin/2to3' To force the link and overwrite all conflicting files:
brew link --overwrite python To list all files that would be deleted:
brew link --overwrite --dry-run python #链接错误 提示有 /usr/local/bin/2to3 需要删除然后重写
$ brew link --overwrite python
Linking /usr/local/Cellar/python/3.7.... symlinks created
#成功之后 查看版本。。
$ python3 --version
Python 3.6. $python --version
Python 3.6. :: Anaconda, Inc. 两种的命令显示的版本不一样。由于之前安装了anaconda,anaconda 之前用的版本python指定了3.6.4,和anaconda绑定的。
现在用brew安装了之后并没有链接到系统变量。
之后又用安装包的格式下载了 python 3.7.
然后
$ python3 --version
Python 3.7.
可见通过官方安装包安装的会自动注册环境变量 经过验证凡是通过安装包安装的都会在下面的目录下:
/Library/Frameworks/Python.framework/Versions/3.4
/Library/Frameworks/Python.framework/Versions/3.6
/Library/Frameworks/Python.framework/Versions/3.7 通过brew 安装的都会在
/usr/local/Cellar/python/3.7.
并且在子目录中
/usr/local/Cellar/python/3.7./Python\ Launcher\ .app
idle 和 Python Launcher

综上,尽量用官方网站提供的安装包,不用做额外的操作,制动链接系统变量