2

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Richard
  • 62,943
  • 126
  • 334
  • 542
  • Possibly paths for `pyenv` are not added into `PATH`. Or `pyenv` has not been initialized correctly. Please check [pyenv's README](https://github.com/pyenv/pyenv#installation) about how to init `pyenv`. – Simba Aug 05 '21 at 07:53
  • There may be system software that still depends on Python2. I'd leave python2 alone and just always use `python3` instead of `python`, but wouldn't alias it as to not break some old code. Macos ships with ancient software, just run `/usr/bin/diff --version`. – Robert Aug 05 '21 at 16:40

1 Answers1

3

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.

Luv_Python
  • 194
  • 6