Search code examples
python-2.7powershell

Python Version in PowerShell


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?

Solution

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