Reputation: 761
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
Upvotes: 19
Views: 73541
Reputation: 953
This was a question about python 2.7, but probably it will be useful to give an answer for the versions above 3.3 too:
Previously, multiple versions (also environments, also they are specific folders) of python on the same system was rare, and placing the 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 activates one of the installed versions automatically. It is supposed to be placed in PATH
instead of any python executable.
So in this modern situation, Get-Command python | fl *
may give you nothing or nothing helpful.
And to run scripts or to get available versions, use launcher:
Get-Command py
command from the PowerShell. If launcher is missing, it can be installed with the official installer. There is a separate checkbox for the launcher which is enabled by default.py --list-paths
will give a summary on the installed versions, and supposed way to run scripts is not previous python main.py
, but commands like py main.py
or py -3.5 main.py
. Run py --help
for more info.Additional confirmation that intended way changed.
Just to give an idea, launcher is not the only way to activate, this also can be done by a simple command.
For example, there is a version under D:\python_install\python.exe
. But it's not in the PATH
and python
command correctly ends with not found error or opens Windows Store. An additional command in cmd or bat SET PATH=D:\python_install\;%PATH%
or PowerShell $env:Path = "D:\python_install\;" + $env:Path
temporarily activates that specific version, and python
will work as previously during that specific run.
Upvotes: 1
Reputation: 1
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.
Upvotes: -3
Reputation: 29048
In PowerShell, Get-Command python | fl *
will tell you which Python executable it's finding and show you details about where it is.
Get-Command
earlier, and decide if you want to remove that.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:
New-Alias -name python -Value C:\Python27\python.exe
, etc).Upvotes: 32