python3 command not found after installing python with pyenv
Asked Answered
C

4

10

I installed a specific version of python with pyenv. When typed pyenv version in terminal, i see 3.5.0 (set by /Users/lcherukuri/.python-version). But when I typed python3, I got python3 command not found. How to fix this? pip3 is Also not found

Cabriolet answered 18/5, 2018 at 18:39 Comment(5)
Is python part of your $PATH? What OS are you on?Clemmy
you need to define an alias for the new environment. Like: gist.github.com/haridas/4966347Outlandish
try 'python' without the 3. It may be that with specific environment python give you python3Vancevancleave
@ArjunAthreya macOSCabriolet
@PaulaThomas just python works. But it uses system 2.7 version. i need python 3.5.0Cabriolet
S
8

If you installed both python 2.x and python 3.x using pyenv, run the following to enable both versions to be found globally (python, python2 and python3 aliases).

Add the specific versions you are using:

pyenv global 3.8.3 2.7.18
Salcedo answered 6/7, 2020 at 7:46 Comment(0)
P
8

pyenv manages shim executables for commands like python3 and pip3. If pyenv's shims aren't available in your shell, it usually means one of two things:

  • pyenv isn't fully installed

or

  • pyenv shell features aren't active

As your pyenv command is working but the shims aren't, it most likely means the shell features aren't activated. As of writing, the correct way is to ensure the init command output is evaluated. On macOS, you can add the following to your ~/.bash_profile:

eval "$(pyenv init -)"

Older installation instructions might not include that step or just have you add pyenv's bin directory to the PATH, which is not enough. If you used pyenv-installer, this step is hinted at in a warning at the end of the installation process.

Pender answered 12/8, 2020 at 19:3 Comment(2)
This answer deserves an award for the amount of concepts, logic, and context included. It saved me so much struggle. Thank you.Basketwork
I needed python 3 (global) and python 2 for a specific app (pyenv local...). Both were installed from pyenv but only python3 command worked. Adding eval "$(pyenv init -)" in bash profile helped to use respective global, local versions. Thanks for sharing useful init command to make both versions work in respective contexts.Astoria
H
3

pyenv is just a Python version manager. It may be able to see a Python 3.X installed even if python3 isn't installed in your $PATH.

You need to add python3 to your $PATH. You can see how to do that here.

By default, MacOS uses python3 to differentiate between the native pre-installed python (which is Python 2.7) and any post-installed Python 3.X distributions. The same goes for pip and pip3.

From the pyenv documentation on managing versions:

Locating the Python Installation

Once pyenv has determined which version of Python your application has specified, it passes the command along to the corresponding Python installation.

Each Python version is installed into its own directory under $(pyenv root)/versions.

For example, you might have these versions installed:

$(pyenv root)/versions/2.7.8/

$(pyenv root)/versions/3.4.2/

$(pyenvroot)/versions/pypy-2.4.0/

As far as pyenv is concerned, version names are simply the directories in $(pyenv root)/versions.

Hypanthium answered 18/5, 2018 at 19:41 Comment(0)
W
2

I had the python3 in path. I also executed pyenv global 2.x.x 3.x.x. But I still got the same error.

What eventually worked for me is executing this line in the project root (with whichever version replacing 3.X.X)

pyenv shell 3.X.X

Note: This sets the shell specific python version so it's not really a solution to the problem posted. Just a workaround to get python3 working.

Wingding answered 19/11, 2020 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.