pyenv-win not overriding system Python version with local setting

27 views Asked by At

I've installed pyenv-win 3.1.1 on Windows using Chocolatey and successfully installed Python 2.6 using pyenv install 2.6. I then tried setting the local Python version for my project by navigating to the project directory and running pyenv local 2.6, which completed without errors.

When I check the versions with pyenv versions, I see:

* 2.6 (set by path\to\project\.python-version)
  3.8.10

indicating that Python 2.6 is correctly set as the local version for my project. Additionally, pyenv which python points to the expected Python executable at C:\Users\<userName>\.pyenv\pyenv-win\versions\2.6\python.exe.

However, when I run python --version in my project directory, it still points to my system Python installation (Python 3.11.7 at C:\Program Files\Python312\python.exe). Running where python yields:

C:\tools\msys64\mingw64\bin\python.exe
C:\Program Files\Python312\python.exe
C:\Users\<userName>\.pyenv\pyenv-win\shims\python
C:\Users\<userName>\.pyenv\pyenv-win\shims\python.bat

I expected that after running pyenv local 2.6, the python command would point to the Python 2.6 version installed via pyenv-win. Can anyone help me understand why pyenv local 2.6 does not seem to override the system Python version as expected in this context?

1

There are 1 answers

0
Foad S. Farimani On

From here, I could find a temporary solution:

set PATH=C:\Users\%USERNAME%\.pyenv\pyenv-win\shims\;%PATH%

of course, if you want a permanent solution, then you have to manually add the above path to your environment variables. However, beware that it can cause some issues, and I do not recommend it.