pyenv:python:找不到命令

新手上路,请多包涵

我想将 Python3 与 pyenv 一起使用。

 $ pyenv root
/Users/asari/.pyenv
$ pyenv versions
  system
  2.7.15
  3.6.2
  3.6.3
  3.6.4
* 3.6.6 (set by /Users/asari/workspace/hoge/.python-version)
$ python -V
pyenv: python: command not found

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

但是,找不到 python 命令。

我在 .pyenv/shims/python 中读到,以为 .pyenv/versions/3.6.6/bin/ 中没有python,但我不知道为什么缺少python。

 $ pwd
/Users/asari/.pyenv/versions/3.6.6/bin
$ ls -la
total 12096
drwxr-xr-x  19 asari  staff      608  8 16 00:51 .
drwxr-xr-x   6 asari  staff      192  8 16 00:51 ..
lrwxr-xr-x   1 asari  staff        8  8 16 00:51 2to3 -> 2to3-3.6
-rwxr-xr-x   1 asari  staff      135  8 16 00:51 2to3-3.6
-rwxr-xr-x   1 asari  staff      276  8 16 00:51 easy_install-3.6
lrwxr-xr-x   1 asari  staff        7  8 16 00:51 idle3 -> idle3.6
-rwxr-xr-x   1 asari  staff      133  8 16 00:51 idle3.6
-rwxr-xr-x   1 asari  staff      258  8 16 00:51 pip3
-rwxr-xr-x   1 asari  staff      258  8 16 00:51 pip3.6
lrwxr-xr-x   1 asari  staff        8  8 16 00:51 pydoc3 -> pydoc3.6
-rwxr-xr-x   1 asari  staff      118  8 16 00:51 pydoc3.6
lrwxr-xr-x   1 asari  staff        9  8 16 00:51 python3 -> python3.6
lrwxr-xr-x   1 asari  staff       16  8 16 00:51 python3-config -> python3.6-config
-rwxr-xr-x   2 asari  staff  3078944  8 16 00:51 python3.6
lrwxr-xr-x   1 asari  staff       17  8 16 00:51 python3.6-config -> python3.6m-config
-rwxr-xr-x   2 asari  staff  3078944  8 16 00:51 python3.6m
-rwxr-xr-x   1 asari  staff     2076  8 16 00:51 python3.6m-config
lrwxr-xr-x   1 asari  staff       10  8 16 00:51 pyvenv -> pyvenv-3.6
-rwxr-xr-x   1 asari  staff      475  8 16 00:51 pyvenv-3.6

$路径

$ echo $PATH | perl -p -e 's/:/\n/g'
/Users/asari/.pyenv/shims
/Users/asari/.pyenv/bin
/Users/asari/.rbenv/shims
/Users/asari/.cargo/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

安装日志

$ pyenv install 3.6.6
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.6.tar.xz...
-> https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
Installing Python-3.6.6...
python-build: use readline from homebrew
Installed Python-3.6.6 to /Users/asari/.pyenv/versions/3.6.6

 $ pyenv --version
pyenv 1.2.7
$ brew list | grep py
python
python@2

pyenv 克隆并从 github 安装(我还没有在 brew 上安装 pyenv)

.zshrc

 # python
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

感谢您的时间。

更新

我创建了 python 的符号链接,python 工作了。

为什么没有 python 符号链接? (我想知道是否安装失败,我正在多次运行安装和卸载

创建符号链接

$ pwd
/Users/asari/.pyenv/versions/3.6.6/bin
$ ln -s python3 python

工作,

 $ pwd
/Users/asari/workspace/hoge
$ python -V
Python 3.6.6

原文由 asari-mtr 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
2 个回答

我解决了。

我在 .zshrc 中使用了以下 grep 选项

export GREP_OPTIONS = '- color = auto'

看来即使在 pyenv 中使用的 grep 的搜索结果中包含 ANSI 转义码,它也没有作为字符串正确使用。

我想你们都知道,但是 GREP_OPTIONS 已被弃用。

原文由 asari-mtr 发布,翻译遵循 CC BY-SA 4.0 许可协议

添加到 ~/.bashrc

 alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"

原文由 4lk4tr43 发布,翻译遵循 CC BY-SA 4.0 许可协议

推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏