This is if you have both the versions installed.
Go to This PC โ Right-click โ Click on Properties โ Advanced System Settings.
You will see the System Properties. From here navigate to the Advanced Tab -> Click on Environment Variables.
You will see a top half for the user variables and the bottom half for System variables.
Check the System Variables and double-click on the Path (to edit the Path).
Check for the path of Python(which you wish to run i.e. Python 2.x or 3.x) and move it to the top of the Path list.
Restart the Command Prompt, and now when you check the version of Python, it should correctly display the required version.
Answer from Aditya Deshpande on Stack OverflowThis is if you have both the versions installed.
Go to This PC โ Right-click โ Click on Properties โ Advanced System Settings.
You will see the System Properties. From here navigate to the Advanced Tab -> Click on Environment Variables.
You will see a top half for the user variables and the bottom half for System variables.
Check the System Variables and double-click on the Path (to edit the Path).
Check for the path of Python(which you wish to run i.e. Python 2.x or 3.x) and move it to the top of the Path list.
Restart the Command Prompt, and now when you check the version of Python, it should correctly display the required version.
The Python installer installs Python Launcher for Windows. This program (py.exe) is associated with the Python file extensions and looks for a "shebang" comment to specify the python version to run. This allows many versions of Python to co-exist and allows Python scripts to explicitly specify which version to use, if desired. If it is not specified, the default is to use the latest Python version for the current architecture (x86 or x64). This default can be customized through a py.ini file or PY_PYTHON environment variable. See the docs for more details.
Newer versions of Python update the launcher. The latest version has a py -0 option to list the installed Pythons and indicate the current default. py -h lists complete Python Launcher options as well as Python options.
Here's how to check if the launcher is registered correctly from the console:
C:\>assoc .py
.py=Python.File
C:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%1" %*
Above, .py files are associated with the Python.File type. The command line for Python.File is the Python Launcher, which is installed in the Windows directory since it is always in the PATH.
For the association to work, run scripts from the command line with script.py, not "python script.py", otherwise python will be run instead of py. If fact it's best to remove Python directories from the PATH, so "python" won't run anything and enforce using py.
py.exe can also be run with switches to force a Python version:
py -3 script.py # select latest Python 3.X version to be used.
py -3.6 script.py # select version 3.6 specifically.
py -3.9-32 script.py # select version 3.9 32-bit specifically.
py -0 # list installed Python versions (latest PyLauncher).
Additionally, add .py;.pyw;.pyc;.pyo to the PATHEXT environment variable and then the command line can just be script with no extension.
Switching between versions of python installed from microsoft store
How to change default python in `py-launcher` at windows?
Switching between Python versions
Change python version
Videos
Generally i was using the latest python version 3.12. in my terminalk
So when i created a virtual environment with
python -m venv xyz
the created virtual environment was under 3.12
For testing purposes it was now necessary to also install python version 3.9.
But now when i am using venv to create a new virtual environment it is the version 3.9.
How can i change the "standard" python-version bakc to 3.12. when i am creating a virtual environment using venv?
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.