python 和 python3 命令没有指向 pyenv 全局版本

python and python3 command does not point to pyenv global version

我之前用自制软件安装了 python 2.7 和 python 3。

我将这些版本添加到 pyenv

ln -s $(brew --cellar python)/* ~/.pyenv/versions
ln -s $(brew --cellar python@2)/* ~/.pyenv/versions

当我使用 pyenv global 3.6.5 设置全局版本时,我在 运行 此命令

上收到以下错误
➜ python --version
pyenv: python: command not found

The `python' command exists in these Python versions:
  2.7.15

我想设置 python 命令指向全球版本。

Homebrew 的 python 公式是 Python 3. 为了避免破坏期望 python 命令的应用程序 运行 Python 2, brew install python 不添加 python 命令,仅添加 python3。这包含在警告中,在 brew info python:

中可见

Python has been installed as /usr/local/bin/python3

Unversioned symlinks python, python-config, pip etc. pointing to python3, python3-config, pip3 etc., respectively, have been installed into /usr/local/opt/python/libexec/bin

仅使用自制程序时,很容易让 python 指向 Python 3,方法是在 shell 配置中添加如下一行:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

因此,一种解决方案可能是 link pyenv 到该目录:

ln -s $(brew --prefix)/opt/python/libexec/bin ~/.pyenv/versions/3-brew

这将使 python 工作。但是,这意味着 python3.6 不会 工作,因为该可执行文件存在于 $(brew --cellar python)/3.6.5 中,所以它不是一个完整的解决方案。我还没有想出任何可以在不手动将 symlinks 添加到 Homebrew 已安装的 Python.

的情况下保留这两种行为的方法