如何使用 Homebrew 在我的 Mac 上默认 Python3.8?

Tac*_*Tau 24 linux macos homebrew python-3.x

我已将我的 python 3 更新到最新版本 3.8:

brew search python
==> Formulae
app-engine-python   gst-python          python ?            python@3.8 ?
boost-python        ipython             python-markdown     wxpython
boost-python3       micropython         python-yq

==> Casks
awips-python               kk7ds-python-runtime       mysql-connector-python

Run Code Online (Sandbox Code Playgroud)

但是当我在我的 mac 上检查 python3 版本时,它仍然显示 3.7:

python3 --version

Python 3.7.6

Run Code Online (Sandbox Code Playgroud)

如何使用 Homebrew 将 python3 默认为最新的 3.8 版本?

编辑:当我尝试使用时brew switch,它告诉我我只安装了 python 3.7.6,但最后brew upgrade我很确定它python3.8.1是用 Homebrew 安装的

brew switch python 3.8.1
python does not have a version "3.8.1" in the Cellar.
python's installed versions: 3.7.6_1
Run Code Online (Sandbox Code Playgroud)

Igo*_*aic 36

这是解决方案:

如果现有符号链接属于 python 3.7,您应该取消链接它们:
brew unlink python

基本上所有你需要做的:
brew link --force python@3.8

或强制链接并覆盖所有冲突文件:
brew link --force --overwrite python@3.8

或者,如果需要,列出将被删除的所有文件:
brew link --overwrite --dry-run python@3.8

因此,您可以切换到 Homebrew 存储库中可用的任何 Python 版本。

另请查看答案以了解pyenv使用情况


Tac*_*Tau 9

好的,感谢来自 Homebrew 社区讨论的@gromgit(https://discourse.brew.sh/t/how-to-default-python-3-8-on-my-mac-using-homebrew/7050

这是解决方案:

$ brew info python@3.8
python@3.8: stable 3.8.1 (bottled) [keg-only]
...
==> Caveats
Python has been installed as
  /usr/local/opt/python@3.8/bin/python3
...
python@3.8 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have python@3.8 first in your PATH run:
  echo 'export PATH="/usr/local/opt/python@3.8/bin:$PATH"' >> ~/.bash_profile

For compilers to find python@3.8 you may need to set:
  export LDFLAGS="-L/usr/local/opt/python@3.8/lib"

For pkg-config to find python@3.8 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/python@3.8/lib/pkgconfig"
Run Code Online (Sandbox Code Playgroud)

python这个时候我会坚持(v3.7.6),等待后续版本v3.8.1的无缝升级。