Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"python" shim is not used if a user has ran it before installing the first alternative version #2732

Open
debnet opened this issue Jun 21, 2023 · 7 comments

Comments

@debnet
Copy link

debnet commented Jun 21, 2023

GNU/Linux Fedora 38 (x86/64), pyenv 2.3.21 (fresh install), gcc 13.1.1

I installed Python version 3.11.4 and use pyenv local 3.11.4 as usual, but shims seem to only use version from the system (3.11.3).

marc@marcbook ~  
$ which python
/usr/bin/python

marc@marcbook ~  
$ python --version
Python 3.11.3

marc@marcbook ~  
$ pyenv install -f 3.11.4
Downloading Python-3.11.4.tar.xz...
-> https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz
Installing Python-3.11.4...
Installed Python-3.11.4 to /home/marc/.pyenv/versions/3.11.4

marc@marcbook ~  
$ pyenv local 3.11.4

marc@marcbook ~ 3.11.4 
$ pyenv rehash

marc@marcbook ~ 3.11.4 
$ which python
~/.pyenv/shims/python

marc@marcbook ~ 3.11.4 
$ python --version
Python 3.11.3

But it works fine with Python 3.12-dev, so I don't really understand what is going on...

marc@marcbook ~
$ pyenv local 3.12-dev

marc@marcbook ~ 3.12-dev
$ pyenv versions
  system
  3.11.4
* 3.12-dev (set by /home/marc/.python-version)

marc@marcbook ~ 3.12-dev 
$ python --version
Python 3.12.0b3+
@native-api
Copy link
Member

Duplicate of #2698 , it looks like

@native-api native-api marked this as a duplicate of #2698 Jun 22, 2023
@debnet
Copy link
Author

debnet commented Jun 22, 2023

It is not. Please re-open.

@native-api
Copy link
Member

native-api commented Jun 22, 2023

We need diagnostic information as per the issue template to say anything more specific.

@native-api
Copy link
Member

native-api commented Jun 23, 2023

I was able to reproduce this in a fresh install of Pyenv in Fedora 38.

The cause was Bash's PATH cache. It was still running /usr/bin/python when you invoke "python" despite the PATH now pointing to a Pyenv's shim.

Run hash -r to fix.

@native-api native-api reopened this Jun 23, 2023
@native-api
Copy link
Member

native-api commented Jun 23, 2023

(Correction:)

Looks like this happens when you

  • start a shell when there are no alt versions installed yet
  • invoke python3/python (the latter -- if your system has the "python" executable)
  • pyenv install an alt version, without running hash -r or restarting your shell afterwards
  • invoke python3/python again

Could you confirm?

@native-api
Copy link
Member

marc@marcbook ~ 3.11.4
$ pyenv rehash

This btw should've fixed the Bash hash issue. Looks like you didn't install Pyenv into your shell as a shell function as per the README and/or not restarted the shell after that.

@debnet
Copy link
Author

debnet commented Jun 23, 2023

I used pyenv installer script and put this into my .bashrc as stated by documentation.

export PYENV_ROOT="$HOME/.pyenv"
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

@native-api native-api changed the title Pyenv local 3.11.4 still use system 3.11.3 but 3.12-dev works fine (shim issue?) "python" shim is not used if a user has ran it before installing an alternative version Sep 19, 2023
@native-api native-api changed the title "python" shim is not used if a user has ran it before installing an alternative version "python" shim is not used if a user has ran it before installing the first alternative version Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants