首页 > 解决方案 > Python3.8.1 已安装但编译器找不到

问题描述

Python 3.8.1 已安装,但它仍然说版本是 2.7.17。我如何实际使用 3.8.1?

$ brew install python@3.8
Warning: python@3.8 3.8.1 is already installed and up-to-date
To reinstall 3.8.1, run `brew reinstall python@3.8`
$ python --version
Python 2.7.17

标签: pythonpython-3.xhomebrew

解决方案


Homebrew 在python3;下安装 Python 3 python除非您明确提出要求,否则它永远不会别名为 Python 3: https ://docs.brew.sh/Homebrew-and-Python#python-3x-or-python-2x

可执行文件的组织方式如下,以便可以安装 Python 2 和 Python 3 而不会发生冲突:

  • python3指向 Homebrew 的 Python 3.x(如果已安装)
  • python2指向 Homebrew 的 Python 2.7.x(如果已安装)
  • python指向 Homebrew 的 Python 2.7.x(如果已安装),否则指向 macOS 系统 Python。检查brew info python您是否希望将 Homebrew 的 3.x python 添加到您的 PATH 中。

brew info python输出之后,您应该能够通过在您的 中添加以下路径来获得指向 Python 3 的未版本化别名$PATH

$(brew --prefix python@3.8)/libexec/bin

也就是说,在您的~/.bash_profileor中添加以下行~/.bashrc

PATH="$(brew --prefix python@3.8)/libexec/bin:$PATH"

启动一个新的 shell,python应该是 Python 3.8。


推荐阅读