Mr. Kennedy Mr. Kennedy - 2 years ago 199
Python Question

How to launch python 2.7 from win7 powershell after installing 3.5?

I just installed python 3.5.1 on a win7 OS which also has python 2.7. Typing "python" into the Powershell now launches 3.5.1. Previously that launched 2.7.

How do I launch python 2.7 now? Typing "python27" or "Python27", "python2.7", "Python2.7" doesn't do it. I do have "C:\Python;" in my user Environment variable.

After reading this discussion: Python 2 and 3 from Powershell
and the referenced article:

Am I correct that Powershell can only do one or the other, i.e. if I want to use 2.7 in Powerhell I have to activate and deactivate it?

Is there is a way to simply type "python27" to launch 2.7?

If it is helpful, this is my user env


C:\Program Files\Common Files\Microsoft Shared\Windows Live;
C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;
C:\Program Files (x86)\Windows Live\Shared;
C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;
C:\Program Files (x86)\Common Files\Roxio Shared\12.0\DLLShared\;
C:\Program Files\WIDCOMM\Bluetooth Software\;
C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;
C:\Program Files (x86)\QuickTime\QTSystem\;
C:\Program Files (x86)\Skype\Phone\;
C:\Program Files\MATLAB\R2015b\bin;

Answer Source

Python installations place a a stub executable named py.exe in $env:SYSTEMROOT (typically: C:\Windows), to which you can pass an option to specify the version you want to run: -2 to launch an installed 2.x version, and -3 for an installed 3.x version (seemingly, the default is the 2.x version).

Thus, given that $env:SYSTEMROOT is normally in the path, use the following to run a Python 2.x script from PowerShell:

py.exe -2 ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download