Richard
Richard

Reputation: 65510

pyenv: version shown does not match actual version?

I am working on OS X 11.4 (Big Sur), and I have installed pyenv and pyenv-virtualenv.

I have also installed Python 3.9.6 via pyenv.

However, although pyenv thinks I am using Python 3.9.6...

% pyenv versions
  system
* 3.9.6 (set by /Users/me/.pyenv/version)

...python is still defaulting to 2.7.16:

% python -V
Python 2.7.16

Some more information:

% pyenv version
3.9.6 (set by /Users/me/.pyenv/version)

% which python
/usr/bin/python

If I do python3 --version then I do see 3.9.6. But I'd prefer it if python defaulted to this too.

What am I doing wrong? Should I just alias python to python3?

Upvotes: 2

Views: 4674

Answers (1)

Luv_Python
Luv_Python

Reputation: 262

You are almost there. You need to configure your shell's environment for Pyenv.

I am going to assume you are on zsh, run these commands:

echo 'eval "$(pyenv init --path)"' >> ~/.zprofile

echo 'eval "$(pyenv init -)"' >> ~/.zshrc

Make sure that your terminal app runs the shell as a login shell. Source: pyenv GitHub

if the version problem persists. Open your ~/.zshrc and paste the following to the bottom:

export PATH="$(pyenv root)/shims:$PATH"

eval "$(pyenv init --path)"
eval "$(pyenv init -)"


if command -v pyenv 1>/dev/null 2>&1; then
    eval "$(pyenv init --path)"
fi

Creating an alias of python to python3 will cause problems for you.

Upvotes: 5

Related Questions