python - 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
命令指向全局版本。
解决方案
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-config
pip
python3
python3-config
pip3
仅使用 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,我还没有想出任何可以保留这两种行为的方法。
推荐阅读
- android - 跨行动态拉伸表格单元格以适应其内容
- java - 如何修复我的应用程序崩溃而不是拨打电话?
- asp.net - 你可以在 ASP 中堆叠多个 IF 语句吗?我的不工作
- highcharts - 显示多行系列时,Highcharts单击事件未触发
- python-3.x - 如何在 Python 3.x 中使用 for 循环来解决这个难题?
- android - 2 orderby 方法在 firebase firestore android 上无法正常工作
- ruby-on-rails - 如何以相同的形式更新表及其关联的联接表?
- sql - 如何在 go-pg 中查询嵌套结构中的子字段(带有 Go 的 Postgres ORM)?
- python - 在 keras 中实现变分自动编码器时出现 InvalidArgumentError
- javascript - 不使用 pop() 从数组中删除最后一个元素