【问题标题】:Python3.8.1 installed but the compiler can't find itPython3.8.1 已安装但编译器找不到
【发布时间】:2020-02-17 22:15:55
【问题描述】:

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

【问题讨论】:

  • python3 --version 呢?
  • 也可以是python38python3.8,以及所有可能的别名
  • 已安装但不在PATH环境变量中(或包含2.7的路径后)
  • 尝试py进入你的命令行看看你是否回到3.8版本,否则你的环境变量可能搞砸了
  • 没有编译器。 shell 和 python 解释器是您在这里处理的两个相关实体。

标签: python python-3.x homebrew


【解决方案1】:

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。如果您希望将 Homebrew 的 3.x python 添加到您的 PATH,请查看 brew info python

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 2017-09-06
    • 2014-09-30
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多