Friday, February 25, 2022

[SOLVED] Pyenv installs the system version instead of the chosen local version

Issue

I am wondering why the wrong version is selected here. Here is some information:

✦ ❯ which python3
/usr/bin/python3

~/ds/test-pyenv
✦ ❯ python3 -V
Python 3.8.10

~/ds/test-pyenv
✦ ❯ pyenv versions
  system
* 3.10.0 (set by /home/bebop/.pyenv/version)
  3.9.9

~/ds/test-pyenv
✦ ❯ pyenv local
pyenv: no local version configured for this directory

~/ds/test-pyenv
✦ ❯ pyenv local 3.10.0

Why is the local version not detected here?

3.8.10 instead of 3.10.0

~/ds/test-pyenv via 🐍 v3.8.10
✦ ❯ python3 -m venv .venv

~/ds/test-pyenv via 🐍 v3.8.10
✦ ❯  source .venv/bin/activate

~/ds/test-pyenv via 🐍 v3.8.10 (.venv)
✦ ❯ which python3
/home/rsale/ds/test-pyenv/.venv/bin/python3

I suspect the problem are these simlinks here but I don't know when they got created. Any ideas on how I should proceed?

~/ds/test-pyenv via 🐍 v3.8.10 (.venv)
✦ ❯ la .venv/bin
lrwxrwxrwx 1 rsale rsale    7 Jan 16 21:01 python -> python3
lrwxrwxrwx 1 rsale rsale   16 Jan 16 21:01 python3 -> /usr/bin/python3

Also I am using WSL2.

Not a duplicate of System python version active instead of local pyenv version

Fernando Espinosa's answer assumes that the local pyenv version was not set, which I am clearly doing.

Edit some more info

✦ ❯pyenv doctor
Cloning /home/rsale/.pyenv/plugins/pyenv-doctor/bin/.....
Installing python-pyenv-doctor...
Installed python-pyenv-doctor to /tmp/pyenv-doctor.20220116232505.7407/prefix

Congratulations! You are ready to build pythons!

✦ ❯pyenv
pyenv 2.2.2
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   --version   Display the version of pyenv
   activate    Activate virtual environment...

✦ ❯which pyenv
pyenv () {
        local command
        command="${1:-}"
        if [ "$#" -gt 0 ]
        then
                shift
        fi
        case "$command" in
                (activate | deactivate | rehash | shell) eval "$(pyenv "sh-$command" "$@")" ;;
                (*) command pyenv "$command" "$@" ;;
        esac
}

Solution

Aliasing pyenv did it

alias pyenv='$PYENV_ROOT/bin/pyenv'

whereas adding pyenv to the path

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

or did not.

export PATH="$PYENV_ROOT/shims:$PATH"

Still wondering why which pyenv failed but pyenv doctor worked.



Answered By - RSale
Answer Checked By - Terry (WPSolving Volunteer)