Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyenv pointing to correct version with "python" but not "python3"

I am using Ubuntu 20.04 so my system version of Python is 3.8.5. I have installed Python 3.9.1 using pyenv and have set up a folder-specific python as follows:

$ pyenv local 3.9.1
$ cat .python-version
3.9.1

Pyenv's shims are present and available in $PATH:

$ which python
/home/username/.pyenv/shims/python
$ which python3
/home/username/.pyenv/shims/python3

Pyenv itself correctly recognises the version that I want to use:

$ pyenv which python
/home/username/.pyenv/versions/3.9.1/bin/python
$ pyenv which python3
/home/username/.pyenv/versions/3.9.1/bin/python3

However, when I run python or python3, only the former gives me the correct version, while python3 reverts to the system version:

$ python --version
Python 3.9.1
$ python3 --version
Python 3.8.5

What could be the problem? I installed pyenv using its own installer (the script at https://pyenv.run) and my .bashrc contains the following lines as per the instructions:

export PATH="/home/username/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
like image 883
JBentley Avatar asked Aug 13 '26 10:08

JBentley


1 Answers

One reason could be that you didn't restart your terminal and the code in your .bashrc hasn't run yet. Try

. ~/.bashrc

or for macOS you use should put it in .zshrc

. ~/.zshrc
like image 184
Chiel Avatar answered Aug 16 '26 02:08

Chiel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!