pyenv:python:找不到命令
pyenv: python :command not found
我想将 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
我解决了
我在 .zshrc
中使用了以下 grep 选项
export GREP_OPTIONS = '- color = auto'
在pyenv
中使用的grep的搜索结果中似乎包含了ANSI转义码,但作为字符串使用起来并不正确
我想你们都知道,但是 GREP_OPTIONS
已被弃用。
当我将 python 与 pyenv 一起使用时,请告诉我:
/Users/zhezhezhu/.pyenv/shims/python: line 21: /usr/local/Cellar/pyenv/1.2.18/libexec/pyenv: No such file or directory
我通过以下方式解决了它:pyenv rehash
添加到 ~/.bashrc
alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"
我使用的是 Ubuntu 20.04,似乎我在 ~/.bashrc
中错误地设置了命令。我关注了 configure your shell's environment for Pyenv:
如果您的 ~/.profile 来源 ~/.bashrc(Debian、Ubuntu、Mint):
# the sed invocation inserts the lines at the start of the file
# after any initial comment lines
sed -Ei -e '/^([^#]|$)/ {a \
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
' -e ':a' -e '$!{n;ba};}' ~/.profile
echo 'eval "$(pyenv init --path)"' >>~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
如果您使用的是 MacOs、Fedora 或 CentOS,请按照 link 以上。 这些命令将来也可能会更改,具体取决于 pyenv/os/distributions 更新。
于 MAC OS。我通过将以下行添加到 ~/.bash_profile
来解决它
在终端调用vi ~/.bash_profile
在行下方插入 2
alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"
保存以上文件后调用此命令source ~/.bash_profile
对我来说,.zshrc.local
文件中的配置需要更新。使用 configure your shell's environment for Pyenv 页面上的信息,我将 pyenv 初始化内容更改为:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
if [ -n "$PS1" -a -n "$BASH_VERSION" ]; then source ~/.bashrc; fi
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
下 mac OS 10.15
我们将以下内容添加到 .bashrc
文件
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
使用Ubuntu18.04环境,这里使用pyenv 2.2.5是你需要更新的.bashrc
:
export PATH="~/.pyenv/bin:$PATH"
if ! command -v pyenv &> /dev/null
then # If no pyenv is found
echo "pyenv could not be found, cannot initialize env"
else
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
如果您正在使用其他 OS,那么您可能需要将其添加到另一个点文件,例如 .bash_profile
。有关更多详细信息,请查看文档:https://github.com/pyenv/pyenv#basic-github-checkout
将以下 2 行添加到 ./zshrc 是答案,因为你已经有了 eval "$(pyenv init -)"
导出 PYENV_ROOT="$HOME/.pyenv"
导出 PATH="$PYENV_ROOT/shims:$PATH"
诀窍是让垫片发挥应有的作用。
我想将 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
我解决了
我在 .zshrc
export GREP_OPTIONS = '- color = auto'
在pyenv
中使用的grep的搜索结果中似乎包含了ANSI转义码,但作为字符串使用起来并不正确
我想你们都知道,但是 GREP_OPTIONS
已被弃用。
当我将 python 与 pyenv 一起使用时,请告诉我:
/Users/zhezhezhu/.pyenv/shims/python: line 21: /usr/local/Cellar/pyenv/1.2.18/libexec/pyenv: No such file or directory
我通过以下方式解决了它:pyenv rehash
添加到 ~/.bashrc
alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"
我使用的是 Ubuntu 20.04,似乎我在 ~/.bashrc
中错误地设置了命令。我关注了 configure your shell's environment for Pyenv:
如果您的 ~/.profile 来源 ~/.bashrc(Debian、Ubuntu、Mint):
# the sed invocation inserts the lines at the start of the file
# after any initial comment lines
sed -Ei -e '/^([^#]|$)/ {a \
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
' -e ':a' -e '$!{n;ba};}' ~/.profile
echo 'eval "$(pyenv init --path)"' >>~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
如果您使用的是 MacOs、Fedora 或 CentOS,请按照 link 以上。 这些命令将来也可能会更改,具体取决于 pyenv/os/distributions 更新。
于 MAC OS。我通过将以下行添加到 ~/.bash_profile
在终端调用vi ~/.bash_profile
在行下方插入 2
alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"
保存以上文件后调用此命令source ~/.bash_profile
对我来说,.zshrc.local
文件中的配置需要更新。使用 configure your shell's environment for Pyenv 页面上的信息,我将 pyenv 初始化内容更改为:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
if [ -n "$PS1" -a -n "$BASH_VERSION" ]; then source ~/.bashrc; fi
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
下 mac OS 10.15
我们将以下内容添加到 .bashrc
文件
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
使用Ubuntu18.04环境,这里使用pyenv 2.2.5是你需要更新的.bashrc
:
export PATH="~/.pyenv/bin:$PATH"
if ! command -v pyenv &> /dev/null
then # If no pyenv is found
echo "pyenv could not be found, cannot initialize env"
else
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
如果您正在使用其他 OS,那么您可能需要将其添加到另一个点文件,例如 .bash_profile
。有关更多详细信息,请查看文档:https://github.com/pyenv/pyenv#basic-github-checkout
将以下 2 行添加到 ./zshrc 是答案,因为你已经有了 eval "$(pyenv init -)"
导出 PYENV_ROOT="$HOME/.pyenv" 导出 PATH="$PYENV_ROOT/shims:$PATH"
诀窍是让垫片发挥应有的作用。