pyenv: python :command not found

Question:

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
Asked By: asari-mtr

||

Answers:

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.

Answered By: asari-mtr

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

Answered By: chaojie

Added to ~/.bashrc

alias python="$(pyenv which python)"
alias pip="$(pyenv which pip)"
Answered By: 4lk4tr43

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.

Answered By: Iman Mirzadeh

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

Answered By: Phat Tran

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)"
eval "$(pyenv init -)"

# Optionally (when you use pyenv virtualenv)
eval "$(pyenv virtualenv-init -)"
Answered By: arno_v

Under mac OS 10.15

We add the following to .bashrc file or .zshrc file

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"

if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
Answered By: zangw

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

Answered By: user1260253

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.

On MacOS Montery 12.5 there is no longer a python binary in /usr/local/bin/. A quick fix is to ensure that is a default ref that points to the system python3.

ln -s python3 /usr/local/bin/python
Answered By: cmcginty

I was experiencing the same error. I just had to follow the error message pyenv was saying:

Note: See 'pyenv help global' for tips on allowing both...

Which made me run the following command:

pyenv global 2.7.18 3.10.6

which are versions existing in my pyenv versions

Answered By: Richard Domingo

In my case shims were initialized correctly:

$ which python
/home/me/.pyenv/shims/python

Yet, similar to richard-domingo’s answer, I was seeing:

$ pyenv which python
pyenv: python: command not found

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

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

The problem here was that the active python version was system, and my system python3 did not have a python alias (symlink).

Two options to fix this:

  • either create a python symlink for the system’s python3, similar to cmcginty’s answer, for example:

    ln -s python3 /usr/bin/python
    
  • or explicitly set the python version to one of the versions listed in the error message, using e.g. pyenv shell, pyenv local, or pyenv global, depending on your use-case. This is explained in the documentation and discussed here and here.

    In this case

    pyenv local 3.8.13
    

    whould create/modify a .python-version file in the current directory.

It is really worth reading the following section in the docs: Understanding Python version selection.

Answered By: djvg

I had previously installed pyenv and then installed my required python distribution as follows:

pyenv install 3.7.10

To remove subsequent pyenv: python :command not found errors — I first had to run:

pyenv global 3.7.10

That solved my problem.

Answered By: Grant Shannon
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.