0

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
  • Check in your path that the pyenv installation is on top of the list (in your user PATH). Also, in my case, I had my system Python in the system PATH, which took priority. Once I removed the system python from PATH, doing python --version in terminal actually returned the pyenv version. Commented Dec 2, 2024 at 14:04

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I know this question has ben answered but just to add a bit to it. I was having a similar issue with the python command not activating the pyenv-win global python version in the shell. Instead it was opening Windows Store to the official Python interpreter & runtime page, because I didn't install Python from any official source, only through pyenv-win.

After some research and digging I found out that the culprit for that was a python.exe in the %USERPROFILE%\AppData\Local\Microsoft\WindowsApps directory that links to the Windows Store page. So because the Windows App directory is above the pyenv directory in the PATH it activates first.

To get rid of it, either:
Delete the python.exe in %USERPROFILE%\AppData\Local\Microsoft\WindowsApps
OR
In Settings > Apps > Advance app setings > Manage App Execution Aliases, toggle off the App Installer Alias for python.exe & python3.exe
OR
As mentioned above, put the pyenv-win directory at the top of the PATH environment variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.