'pyenv: python :command not found
I want to use Python3 with 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
but, python command not found.
I read it in .pyenv/shims/python
, thought that there was not python in .pyenv/versions/3.6.6/bin/
, but I did not know why python was missing.
$ 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
$PATH
$ 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
install log
$ 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 clone and installed from github(I have not installed pyenv on brew)
.zshrc
# python
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Thank you for your time.
UPDATE
I created python
's symlink, and python worked.
Why is there no python
s symlink?
(I was wondering if install failed, I am running install and uninstall many times
create symlink
$ pwd
/Users/asari/.pyenv/versions/3.6.6/bin
$ ln -s python3 python
Work,
$ pwd
/Users/asari/workspace/hoge
$ python -V
Python 3.6.6
Solution 1:[1]
I solved it.
I used the following grep option in .zshrc
export GREP_OPTIONS = '- color = auto'
It seems that even if ANSI escape code was included in the search result of grep used in pyenv
, it was not used properly as a character string.
I think that you all know, but GREP_OPTIONS
is deprecated.
Solution 2:[2]
Added to ~/.bashrc
alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"
Solution 3:[3]
on MAC OS. I solved it by adding to below lines to the ~/.bash_profile
At the terminal call vi ~/.bash_profile
Insert 2 below lines
alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"
Call this command after saving above file source ~/.bash_profile
Solution 4:[4]
when I use python with pyenv, show me:
/Users/zhezhezhu/.pyenv/shims/python: line 21: /usr/local/Cellar/pyenv/1.2.18/libexec/pyenv: No such file or directory
I solved it by : pyenv rehash
Solution 5:[5]
For me the config in my .zshrc.local
file needed an update. Using the info on configure your shell's environment for Pyenv page I changed the pyenv init stuff to this:
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 -)"
Solution 6:[6]
Under mac OS 10.15
We add the following to .bashrc
file
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
Solution 7:[7]
I was using Ubuntu 20.04 and it seemed like I had wrongly setup the commands in my ~/.bashrc
. I followed configure your shell's environment for Pyenv:
If your ~/.profile sources ~/.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
If you are using MacOs, Fedora, or CentOS, please follow the link above. The commands may also change in the future, depending on pyenv/os/distributions udpates.
Solution 8:[8]
Using Ubuntu 18.04 environment, using pyenv 2.2.5 here is what you need to update the .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
If you are using some other OS, then it may be that you need to add this to another dotfile such as .bash_profile
. For more detailed info, check out the docs: https://github.com/pyenv/pyenv#basic-github-checkout
Solution 9:[9]
add below 2 lines to ./zshrc IS THE ANSWER, GIVEN THAT you already have eval "$(pyenv init -)"
export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/shims:$PATH"
Trick is to let shims play its deserving part.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow