System not using pyenv shim

Hello, I’m trying to set up pyenv to use python 3.9.10. which python still shows the path to /usr/bin/python, which is version 3.10.2, so it looks like the shim is not working. I have added this to the ~/bash.rc file:

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

I have set the python version to 3.9.10:

$ pyenv versions
  system
* 3.9.10 (set by /home/lee/.pyenv/version)

Thank you, folks.

First welcome to the community!

Next, what is ~/bash.rc? Does that actually get sourced by bash?

Is there a reason you didn’t follow the instructions from the site?

Those recommend this:

sed -Ei -e '/^([^#]|$)/ {a \
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
' -e ':a' -e '$!{n;ba};}' ~/.bash_profile
echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init --path)"' >> ~/.profile

echo 'eval "$(pyenv init -)"' >> ~/.bashrc
1 Like

Hello Dalto,

Thanks for replying.

I was doing what I could to follow this tutorial: https://realpython.com/intro-to-pyenv/
Regarding bash:

None of the script you posted is on there. Besides, Arch based is not mentioned at all.

I’ll have a go with your script. Thank you.

1 Like

I uninstalled pyenv, and then followed the instructions here:

  1. Double checked the prerequisites were installed - yes
  2. Use the autoinstaller and follow instructions - yes
  3. I had to add these lines to ~/.bashrc as without them pyenv could not be found
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"

which python now points to /home/lee/.pyenv/shims/python
python -V now returns Python 3.9.10 instead of 3.10.2 :grinning: