In PowerShell, Get-Command python | fl * will tell you which Python executable it's finding and show you details about where it is.
- 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.
- 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-Commandearlier, and decide if you want to remove that. - How PowerShell chooses what to run when you type a command is explained in help about_Command_Precedence, and is:
- Alias
- Function
- Cmdlet
- 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:
- make it the only Python version available.
- move its folder to the front of the PATH list, ahead of any other version. See: What are path and other environment variables, and how can I set or use them - question on SuperUser.com
- make a batch file to launch it called python.bat in a folder in the PATH ahead of other versions.
- make an alias (in your PS Profile) named python to launch the one you want (
New-Alias -name python -Value C:\Python27\python.exe, etc).
In PowerShell, Get-Command python | fl * will tell you which Python executable it's finding and show you details about where it is.
- 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.
- 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-Commandearlier, and decide if you want to remove that. - How PowerShell chooses what to run when you type a command is explained in help about_Command_Precedence, and is:
- Alias
- Function
- Cmdlet
- 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:
- make it the only Python version available.
- move its folder to the front of the PATH list, ahead of any other version. See: What are path and other environment variables, and how can I set or use them - question on SuperUser.com
- make a batch file to launch it called python.bat in a folder in the PATH ahead of other versions.
- make an alias (in your PS Profile) named python to launch the one you want (
New-Alias -name python -Value C:\Python27\python.exe, etc).
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:
- ensure you have it:
tryGet-Command pycommand 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. - if install is correct, command
py --list-pathswill give a summary on the installed versions, and supposed way to run scripts is not previouspython main.py, but commands likepy main.pyorpy -3.5 main.py. Runpy --helpfor 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.
switching from python 2 to python 3 in windows powershell
How can I set the default Python version that gets launched when typing python3 (On Windows 11)?
Why doesn't python 3.10.0 show up on PowerShell?
Switching between versions of python installed from microsoft store
In powershell, enter the following:
$Env:PY_PYTHON = 2
Then try using the command "py". It should start up Python 2.7. If you ever want to run Python 3.3 again, "py -3" will do the trick.
Something like Python Select? Windows support is experimental but it might be worth a try.
https://github.com/Activestate/pythonselect
There's also switchpy, although that only supports up to Python 3.2.
apipes.blogspot.com/2010/10/switchpy.html?m=1
correction: ment to say python 3 to python 2
Hi, I'm a beginner at python and currently progressing through learnpythonthehardway in which he uses python 2. Currently when I type python in powershell I'm in version 3.5.1 but I want to switch to version 2. I've tried http://stackoverflow.com/questions/13328258/powershell-python-change-version-used?answertab=active#tab-top
after i type $Env:Python =2 it says to use the command py and it should start up the 2.7 python but i get the error
py : The term 'py' is not recognized as the name of a c spelling of the name, or if a path was included, verify At line:1 char:1
-
py
-
~~
-
CategoryInfo : ObjectNotFound: (py:Strin
-
FullyQualifiedErrorId : CommandNotFoundException
So im wondering if someone can either point out a mistake im making or if there is a simple way to switch over to python 2 other than removing all python files and reinstalling the 2.7 version.
windows 10 Pro
-
This is most likely due to the path variable. You can see this in a command window by typing
Path
at your prompt.
To update the settings,
- Open the 'System' properties.

- Open Environment Variables

- Highlight the 'Path' Variable and click edit.

- Edit the values for the Python entries, to point to the desired python version.

- OK on all boxes, close any CMD windows open, and open new one. Python command should now reference the correct location.
Solution refers to Windows 10, but is essentially the same on Windows 7 +
I was having the same issue as the older python executable was in my system space (which I have no access to) and the newer version is in the user space.
The work around I thought of was to create a .bat file which will open a CMD window in the user space python version.
new_python.bat:
@set "PATH=C:\Users\USER\AppData\Local\Programs\Python\Python39\;C:\Users\USER\AppData\Local\Programs\Python\Python39\Scripts\;%PATH%"
@cmd /k python --version
Does a decent job for me. Just change the first two lines in the PATH variable to your Python directory and the Python Scripts directory. The CMD which will open using this bat will be ready to run the newer version of python executable.
Possibly because after python 3.3 intended command is not python, but simply py
Detailed explanation here
And short answer to your question:
check if powershell command py -0p --list-paths finds any versions.
I am using Windows 11, Python3.10 and Laptop, and Windows Powershell cannot show Python version (command: python --version).
Solution: type Python inside Windows Powershell, it will prompt out Microsoft Store, just click "get", wait to finish the process, then go to Windows Powershell, type "python --version", it can show the Python version.