Python Forum

Full Version: python and py report different versions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've installed Python 3.7.5 on a Windows 10 machine. No other version of Python was ever installed on that machine that I know of (and no-one else uses it). On the Windows Command Prompt, when I query the version with python -V I get Python 2.4.5, while when I use py -V I get Python 3.7.5.

I'd like to know why because I know that one can tie oneself in knots when packages (e.g. pip) detect the 'wrong' version.

What I have in my system's PATH is %homepath%\AppData\Local\Programs\Python\Python37\, and the same with Scripts\ appended.

Thanks
try python3 -V on your prompt, i guess it´ll give you Python3.7.5
and you definitely have python 2 version 2.4.5 on that os.
If there isn´t a specific path in PATH, then the python 2 installation is probably somewhere in your windows system directory. Good luck searching for it.
Thanks ThomasL. Tried python3 -V and got Python 3.8.0! I've started a full search of my registry and found so far that LilyPond (a music notation software I use) has Python 2.4.5 in it's usr\bin\, which is also on my PATH before that of my Python 3.7.5. I assume swapping these would help, but as for the Python 3.8.0... I'll first complete the search of my registry to see what comes up.

Yes, Computer\HKEY_CLASSES_ROOT\Python\shell\open\command has "C:\Program Files (x86)\LilyPond\usr\bin\python.exe" "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9", which is Python 2.4.5.
After a directory and register search, I found that Lilypond and MinGW had installed 'behind my back' Python 2.4.5 and Python 3.8.0, respectively. Since new paths in Windows are appended to the PATH environment variable and I installed Python 3.7.5 last, invoking python.exe resolved to the one in Python 2.4.5 (because I had installed Lilypond before MinGW) and python3.exe to the one in Python 3.8.0 (because there is no python3.exe in Python 2.4.5). As for py.exe, it is in the Windows directory (which has priority over all others) and I assume that (along with pyw.exe) it is replaced by the last Python installed, in this case Python 3.7.5.

The fix has been to move the path of the Python 3.7.5 (which is the one I need at the moment to be the default in my system) higher up in PATH than those of Python 2.4.5 and 3.8.0, and also to ammend the registry keys Computer\HKEY_CLASSES_ROOT\py_auto_file\shell\open\command and Computer\HKEY_CLASSES_ROOT\Python\shell\open\command so that their values point to the python.exe in my Python 3.7.5. (Warning: Tampering with the registry can hang the system.)

Problem solved.

In short: Make sure that the path of the Python you want to be the default in your system is higher up in PATH than that any other, keeping in mind that all sorts of programs install Python for their own use.