2

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: http://windowsitpro.com/powershell/take-charge-environment-variables-powershell

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 PATH:

C:\Users\patrick\AppData\Local\Programs\Python\Python35-32\Scripts\;
C:\Users\patrick\AppData\Local\Programs\Python\Python35-32\;
C:\ProgramData\Oracle\Java\javapath;
C:\Program Files\Common Files\Microsoft Shared\Windows Live;
C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
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;
C:\ffmpeg\bin;
C:\Python27;
C:\SQLite3
8
  • 1
    python.exe from the 32-bit Python 3.5 installation is found in the second PATH entry, while python.exe from Python 2.7 is found in the second to last entry. You can use py -2 to run Python 2.7, or manually modify your system and user PATH values to prioritize 2.7 over 3.5. Note that your per-user value gets concatenated to the end of the system value when you log on. Commented Jun 4, 2016 at 3:36
  • 1
    Also, you have a redundant and broken entry for PowerShell (the 3rd entry), which you can remove. Commented Jun 4, 2016 at 3:38
  • You can try navigating to the directory where 2.7 is installed and then executing it through cmd. Commented Jun 4, 2016 at 4:02
  • 1
    The core Windows developers have always been against using python2.exe, python2.7.exe, and so on, so that isn't going to happen. But you can make these copies for yourself if you prefer that to using py.exe. But leave scripts associated with py.exe because it handles shebangs (including virtual ones such as #!/usr/bin/python3). Commented Jun 4, 2016 at 4:42
  • 1
    PowerShell doesn't search for executables in the current directory. Neither does cmd if you set the environment variable NoDefaultCurrentDirectoryInExePath. That's why it's .\idle instead of idle. But really there's no need to use the batch file. You can use pyw -3 -m idlelib. For Python 2 use pyw -2 -m idlelib.idle; you have to run the idle.py script since Python 2 doesn't grok __main__.py scripts. Commented Jun 4, 2016 at 7:22

2 Answers 2

3

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 ...
Sign up to request clarification or add additional context in comments.

1 Comment

*.exe...? So verbose ;)
1

For the sake of simplicity, I would suggest you use WinPython distribution. There is a winpython command prompt bundled inside. You can open the It in the specific Python version and that Python will be invoked!

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.