首页 > 解决方案 > python和python3命令不指向pyenv全局版本

问题描述

我以前用自制软件安装了 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命令指向全局版本。

标签: pythonpyenv

解决方案


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

Python 已安装为 /usr/local/bin/python3

分别指向,等的未版本化符号链接 , 等 已安装python到/usr/local/opt/python/libexec/binpython-configpippython3python3-configpip3

仅使用 homebrew 时,很容易python通过在 shell 配置中添加这样的行来指向 Python 3:

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

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

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

这将使python工作。但是,这意味着这python3.6 不起作用,因为该可执行文件重新存在于 中$(brew --cellar python)/3.6.5,所以它不是一个完整的解决方案。如果不手动将符号链接添加到 Homebrew 已安装的 Python,我还没有想出任何可以保留这两种行为的方法。


推荐阅读