14

I am previously running python 2.7.11 on Windows 10.

Today, I downloaded and installed python 2.7.13, but the PowerShell version is still at 2.7.11:

python --version
Python 2.7.11
  1. How do I check all installed python versions on my PC?
  2. How do I uninstall python 2.7.11?
  3. How do i set python 2.7.13 as default python version to launch in PowerShell?
Lachie White
  • 1,246
  • 2
  • 14
  • 21
Yeile
  • 608
  • 1
  • 6
  • 20

3 Answers3

29

In PowerShell, Get-Command python | fl * will tell you which Python executable it's finding and show you details about where it is.

  1. You can check Settings -> Apps and Features, or Control Panel -> Programs and Features. They will show you distinct versions of Python you installed, but that might not be enough if Python is installed as part of some other toolkit or program.
  2. If Python 2.7.11 is there, select it and click uninstall. If it's not there, see if you can tell what it's installed with, from the output of Get-Command earlier, and decide if you want to remove that.
  3. How PowerShell chooses what to run when you type a command is explained in help about_Command_Precedence, and is:
    1. Alias
    2. Function
    3. Cmdlet
    4. Native Windows commands

At the point of "Native Windows commands", it goes to the PATH environment variable, a semi-colon separated list of path names, which get searched in order, looking for a matching executable file.

You can see the folders with:

$Env:PATH -split ';'

And you can watch PowerShell identify what to run for 'python' with the command

Trace-Command –Name CommandDiscovery –Expression {get-command python} -PSHost

So, to make Python 2.7.13 the one to launch, you could:

Community
  • 1
  • 1
TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
  • @TessellatingHeckler, it works! Thanks (: Btw.. is there a generic name for these shell commands for python? I would love to learn more about these things, but the resources for learning python seem to not cover them. – Yeile Feb 24 '17 at 05:51
  • @Yeile That's good. I'm not quite sure what you're asking; the generic term for that one `python(.exe)` file you run is [The Python Interpreter](https://docs.python.org/3/tutorial/interpreter.html). I'm not sure Python has many other executables by default unless you install [packages](https://pypi.python.org/pypi?). Not sure there really is a term for Python related tools ? – TessellatingHeckler Feb 24 '17 at 06:17
0

This was a question about python 2.7, but probably will be useful to give an answer for versions above 3.3 too:

Previously, having multiple versions of python installed was rare and placing only available python.exe directly in PATH was acceptable. Currently, multiple installed python versions will conflict and override each other if simply placed that way.
After 3.3 a python launcher was introduced which detects and runs required versions automatically. It is supposed to be placed in PATH instead of specific python executable.

It is probably best now not to have any python.exe avaliable by default, but to activate availability temporary. For example, you have one of many python versions under D:\python_install\python.exe. In batch by default python command correctly ends with not found error, but after additional command SET PATH=D:\python_install\;%PATH% starts to work as previously.

So in this modern situation, Get-Command python | fl * may give you nothing or nothing helpful. And to run scripts or to get avaliable versions, use launcher:

  • ensure you have it: test via Get-Command py command from PowerShell. If launcher is missing, ensure it with checkbox in official installer.
  • if install is correct, command py -0p --list-paths will give good summary on installed versions, and supposed way to run scripts is not previous python main.py, but commands like py -3.5 main.py. Run py --help for more info.

Additional confirmation that intended way changed.

halt9k
  • 527
  • 4
  • 13
-3

I execute the powershell command line statement in python3.8,

import subprocess
subprocess.call('powershell.exe Get-WmiObject Win32_PnPSignedDriver| select DeviceName, Manufacturer, DriverVersion', shell=True)

The running result is:

'select' is not an internal or external command, nor an executable program or batch file.
Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
Paul
  • 1