6

I'm on Windows 7. I have Python 2.7 installed for years. I installed recently Python 3.4. I'm trying to use the new py launcher. When I open the cmd terminal and type py -2, I get this error message: Requested Python version (2) not installed. How can make py aware of my python 2.7 installation?

Note: python 2.7 is installed in a non-standard directory (not in C:\Python27), in case this is the problem.

Dan737
  • 471
  • 4
  • 7
  • 27
  • I tried installing 2.7.8 in a nonstandard directory (literally `C:\Python_non_standard_directory`) and made sure the `Add python.exe to Path` option was unchecked. The result of that install was that `py -2` still worked as expected, as did `py -3`. Unfortunately, I don't have any recommendations, but I thought that my test might help put you on the right track. – Matthew Champion Dec 16 '14 at 11:07
  • Just to clarify: did you install python 2.7.8 after installing python 3? – Dan737 Dec 16 '14 at 15:21
  • I had Python 3.4.1 installed to begin with before installing 2.7.8. – Matthew Champion Dec 16 '14 at 15:27
  • if python3 was installed first then just uninstall the pylauncher and modify python3 in controlpanel – Smart Manoj Jul 09 '17 at 09:31

4 Answers4

10

I found the solution. The registry had wrong entries. As I have a 32 bit version installed I went to HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER\SOFTWARE\wow6432node\Python\PythonCore\2.7\InstallPath and the value was set to C:\Python27 while my installation is in D:\Python27. So I changed all the registry values to match the correct location and it now works fine.

It's been quite a while I installed Python 2.7, but I assume I had Python 2.7 installed first. Then I deleted it and installed pythonxy in this new location. I probably didn't uninstall the previous version correctly.

Dan737
  • 471
  • 4
  • 7
  • 27
  • This also works to get py.exe to run an anaconda version of python. Just add the appropriate key and point it to the anaconda path. – poleguy May 02 '17 at 15:12
  • 2
    There are actually _three locations_ in the registry, and the `py launcher` picks from HKCU according to https://www.python.org/dev/peps/pep-0514/#structure – TT-- Oct 01 '17 at 02:12
5

I had a similar issue with Py Launcher failing to recognize my Python 2.7 install. I found editing the Windows Registry (Windows 10) by adding 2.7 to [HKEY_CURRENT_USER\Software\Python\PythonCore\2.7] solved my problem.

Other Window versions may have the PythonCore key in a different location.

Here is the full export of the tree I added:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Python\PythonCore\2.7]

[HKEY_CURRENT_USER\Software\Python\PythonCore\2.7\InstallPath]
"ExecutablePath"="C:\\Users\\kcec11\\Python\\Python27\\python.exe"
"WindowedExecutablePath"="C:\\Users\\kcec11\\Python\\Python27\\pythonw.exe"
@="C:\\Users\\kcec11\\Python\\Python27\\"
Marcello B.
  • 4,177
  • 11
  • 45
  • 65
Carl C
  • 51
  • 1
  • 2
0

Usually, this kind of problem in Windows occurs because Python isn't in the OS path defined as an environment variable.

As in this question, try going to the "Advanced System Settings", edit "Environment Variables" and include ;C:\python27 (in your case, the place where you installed Python 2.7) to the path.

Community
  • 1
  • 1
Matheus Portela
  • 2,420
  • 1
  • 21
  • 32
  • My python path is D:\Python27. If I run from the terminal `echo %PATH%` I can find `D:\Python27`. Also I can run python 2 from the terminal by typing `python`. – Dan737 Dec 16 '14 at 15:18
0

Old question, another answer - trying out my codebase which I've been using with 3.8.3 for quite a while and I was wanting to test with 3.9.1 because I've experienced getting too far behind the version number curve before to want to experience it again, so using a clean env with just 3.9.1 installed, trying to run from source it gave this error:

Requested Python version (3.8) is not installed

After fifteen minutes of head scratching and searching without any result, and I already can't remember why I checked this but it turns out I had a shebang in line 1 of my main .py file (I'm on Windows):

#!/usr/local/bin/python3.8

change this to:

#!/usr/local/bin/python3.9

and now it works with Python 3.9.1 :-)

See https://docs.python.org/3/using/windows.html