As you can see, I have both Python2 and Python3 installed.


I hope you know that the path of the python executable has to be added to the PATH environment variable in Windows. As you can see, the path of Python2 is placed above the path of Python3 in my system.

How does the cmd run commands?
It searches for an executable with the same name in the directory the cmd has been opened in, then goes and searches for the command in the locations provided in the Windows PATH variable, from TOP to BOTTOM. Which means, it gets the path to Python2 before it can get to the path of Python3. Therefore, every time you type python in your cmd, it runs Python2.
Both Python2 and Python3 executables have the same name in Windows so it never runs python3.

What seems like an obvious solution?
You might think, changing the name of python.exe to python3.exe for the Python3 executable will solve your problem. You are partially right, it will work. But you have to use python3 file.py or python3 --version, which I think, is understandable. But, pip will no longer work if you change the name of the original python executable. You will no longer be able to install external packages and modules.

How can this problem be solved?
You can create an alias for the Python3 executable called python3.bat.
.exe and .bat files can be called from the cmd directly without using their extension. We always write python filename.py instead of python.exe filename.py although both are correct. The same can be done with .bat files.
Go back to the first image and notice the python3.bat file below python.exe. That is my way of calling python3 without renaming my original python executable.

python3.bat
Create a new file using notepad or something and paste this %~dp0python %*
I don't fully understand how this works except that dp0 basically runs python from inside the same directory and %* passes all the arguments to the python executable. Place this file inside your Python3 installation directory and your problem will hopefully be solved.


python3 basically runs your python3.bat file, which in turn runs the python.exe from its folder and passes the arguments to it.

I hope this solves your problem.

Answer from Diptangsu Goswami on Stack Overflow
Top answer
1 of 7
32


As you can see, I have both Python2 and Python3 installed.


I hope you know that the path of the python executable has to be added to the PATH environment variable in Windows. As you can see, the path of Python2 is placed above the path of Python3 in my system.

How does the cmd run commands?
It searches for an executable with the same name in the directory the cmd has been opened in, then goes and searches for the command in the locations provided in the Windows PATH variable, from TOP to BOTTOM. Which means, it gets the path to Python2 before it can get to the path of Python3. Therefore, every time you type python in your cmd, it runs Python2.
Both Python2 and Python3 executables have the same name in Windows so it never runs python3.

What seems like an obvious solution?
You might think, changing the name of python.exe to python3.exe for the Python3 executable will solve your problem. You are partially right, it will work. But you have to use python3 file.py or python3 --version, which I think, is understandable. But, pip will no longer work if you change the name of the original python executable. You will no longer be able to install external packages and modules.

How can this problem be solved?
You can create an alias for the Python3 executable called python3.bat.
.exe and .bat files can be called from the cmd directly without using their extension. We always write python filename.py instead of python.exe filename.py although both are correct. The same can be done with .bat files.
Go back to the first image and notice the python3.bat file below python.exe. That is my way of calling python3 without renaming my original python executable.

python3.bat
Create a new file using notepad or something and paste this %~dp0python %*
I don't fully understand how this works except that dp0 basically runs python from inside the same directory and %* passes all the arguments to the python executable. Place this file inside your Python3 installation directory and your problem will hopefully be solved.


python3 basically runs your python3.bat file, which in turn runs the python.exe from its folder and passes the arguments to it.

I hope this solves your problem.

2 of 7
6

You should have python3 also in your path. You could use python3 to run your script:

python3 <your_script>

But to answer your question, you could use alias and update it as python.

$ python --version    
Python 2.7.6
$ alias python=python3
$ python --version    
Python 3.6.4
🌐
Reddit
reddit.com › r/learnpython › change actual python-version in cmd?
r/learnpython on Reddit: Change actual python-version in cmd?
May 21, 2024 -

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?

Discussions

How to change default python in `py-launcher` at windows?
Hello, I tried to install multiple python versions on my windows machine, I have this version: ❯ py --list -V:3.11 * Python 3.11 (64-bit) -V:3.10 Python 3.10 (64-bit) -V:3.9 Python 3.9 (64-bit) How do I change the default python version to 3.10 when I type py in terminal? because if I type ... More on discuss.python.org
🌐 discuss.python.org
3
0
May 20, 2022
Switching between versions of python installed from microsoft store
So I installed python 3.9 and 3.7 from the microsoft store because I need both versions for certain projects, and I am wondering if it is possible to switch between which version of python I want my system to use. More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
February 8, 2021
windows - How to run different python versions in cmd - Stack Overflow
How can I configure windows command dialog to run different python versions in it? For example when I type python2 it runs python 2.7 and when I type python3 it runs python 3.3? I know how to confi... More on stackoverflow.com
🌐 stackoverflow.com
Changing default version of python from 2,7.16 to 3.12.1
my default py version changes back to 2.7.16 thou i have tried many ways it works till i close terminal but then jumps default version back to 2.7.16 can any one help me on this how to permanently change my default to python3 thankyou More on discuss.python.org
🌐 discuss.python.org
6
0
January 5, 2024
🌐
Python.org
discuss.python.org › python help
How to change default python in `py-launcher` at windows? - Python Help - Discussions on Python.org
May 20, 2022 - Hello, I tried to install multiple python versions on my windows machine, I have this version: ❯ py --list -V:3.11 * Python 3.11 (64-bit) -V:3.10 Python 3.10 (64-bit) -V:3.9 Python 3.9 (64-bit) How do I change the default python version to 3.10 when I type py in terminal? because if I type ...
Top answer
1 of 3
54

I also met the case to use both python2 and python3 on my Windows machine. Here's how i resolved it:

  1. download python2x and python3x, installed them.
  2. add C:\Python35;C:\Python35\Scripts;C:\Python27;C:\Python27\Scripts to environment variable PATH.
  3. Go to C:\Python35 to rename python.exe to python3.exe, also to C:\Python27, rename python.exe to python2.exe.
  4. restart your command window.
  5. type python2 scriptname.py, or python3 scriptname.py in command line to switch the version you like.
2 of 3
26

Python 3.3 introduces Python Launcher for Windows that is installed into c:\Windows\ as py.exe and pyw.exe by the installer. The installer also creates associations with .py and .pyw. Then add #!python3 or #!python2 as the first lline. No need to add anything to the PATH environment variable.

Update: Just install Python 3.3 from the official python.org/download. It will add also the launcher. Then add the first line to your script that has the .py extension. Then you can launch the script by simply typing the scriptname.py on the cmd line, od more explicitly by py scriptname.py, and also by double clicking on the scipt icon.

The py.exe looks for C:\PythonXX\python.exe where XX is related to the installed versions of Python at the computer. Say, you have Python 2.7.6 installed into C:\Python27, and Python 3.3.3 installed into C:\Python33. The first line in the script will be used by the Python launcher to choose one of the installed versions. The default (i.e. without telling the version explicitly) is to use the highest version of Python 2 that is available on the computer.

Find elsewhere
🌐
Python.org
discuss.python.org › python help
Changing default version of python from 2,7.16 to 3.12.1 - Python Help - Discussions on Python.org
January 5, 2024 - my default py version changes back to 2.7.16 thou i have tried many ways it works till i close terminal but then jumps default version back to 2.7.16 can any one help me on this how to permanently change my default to py…
Top answer
1 of 16
191

This is if you have both the versions installed.

Go to This PCRight-clickClick on PropertiesAdvanced 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.

2 of 16
120

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.

🌐
Mostly Python
mostlypython.com › updating-python
Updating Python
August 7, 2025 - First, let's see what my current python command points to: $ python -V Python 3.12.8 $ which python /Users/eric/.pyenv/shims/python · The -V flag shows the current version, and the which command shows the path to the actual python executable.
🌐
CircleCI
support.circleci.com › hc › en-us › articles › 16708605403035-How-to-Change-your-Python-Version-within-the-Windows-Executor
How to Change your Python Version within the Windows Executor – CircleCI Support Center
February 2, 2026 - - run: name: installed version verification shell: bash command: | py -3.9 -m venv venv39 source ./venv39/Scripts/activate python --version
🌐
Python
docs.python.org › 3 › using › windows.html
4. Using Python on Windows — Python 3.14.3 documentation
Once you have installed the Python Install Manager, the global python command can be used from any terminal to launch your current latest version of Python. This version may change over time as you add or remove different versions, and the py list command will show which is current.
🌐
Delft Stack
delftstack.com › home › howto › python › change python version
How to Change Python Version | Delft Stack
March 11, 2025 - Once activated, any Python commands you use will reference the version specified when creating the virtual environment. ... Using virtual environments is a best practice in Python development. It prevents dependency conflicts and ensures that your projects can run smoothly regardless of the global Python installation on your system. If you want to change the global Python version on your system, you can do so using pyenv.
🌐
BlueVPS
bluevps.com › blog › how to update the python version: step-by-step guide install python and upgrade python version
How to Update the Python Version - Blog - BlueVPS
So, let’s discuss how to update your Python version using the above-mentioned methods in detail. It’s essential to check the current Python version running on your computer before updating Python. To check the Python version on Windows, press the “Windows + R” keys, type “cmd” in the text box, and hit “Enter.”
🌐
Hostnoc
hostnoc.com › home › guide › how to update your python version in cmd: 3 powerful steps
How To Update Your Python Version In CMD: 3 Powerful Steps
July 19, 2024 - Select the version you want to install and click the download link for the Windows installer. Locate the downloaded installer file and run it. In the installer window, make sure to check the “Add Python to PATH” option. This ensures that you can run Python from the command line. Choose the “Upgrade Now” option to replace the current version of Python with the new one.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-update-python-on-windows
How to update Python on Windows? - GeeksforGeeks
July 23, 2025 - In this article, we are going to see how to update Python in the Windows system. For the sake of example, we will be upgrading from Python 3.6.8 to Python 3.9.6. Here, we will see how to upgrade the Python version.
🌐
Psspy
psspy.org › psse-help-forum › question › 10719 › change-the-python-version-or-interpreter-on-psse-command-prompt
Change the python version or interpreter on pss/e command prompt - Python for PSSE help forum
March 15, 2025 - @rem run3539.bat @rem psspath35=C:\Program Files\PTI\PSSE35\35.6\PSSBIN\psse35 @rem psspltpath35=C:\Program Files\PTI\PSSE35\35.6\PSSBIN32\pssplt35 @echo OFF Set PSSEVERSION=35 set MINOR=.6 set PYVER=39 set appdata= Set PYTHONCODE=C:\Users\jsm20\Documents\Code\Python\ @rem Set PYTHONHOME=C:\ProgramData\Anaconda3_64bit\ Set PYTHONHOME=%LOCALAPPDATA%\Programs\Python\Python%PYVER%\ SET PSSEROOT=C:\Program Files\PTI\PSSE%psseversion%\%psseversion%%MINOR% SET PSSEPATH=%PSSEROOT%\PSSBIN set psspltpath=%PSSEROOT%\PSSBIN32\ SET PSSPYPATH=%PSSEROOT%\PSSPY%PYVER%\ SET PATH=%PYTHONHOME%;%PYTHONHOME%SCRIP
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 13781
How to change python version : Forums : PythonAnywhere
January 16, 2019 - If you're running it from bash, use the python3.8 command instead of just python · If you're running it fun the editor, see this help page · If you want to use it for a website you've set up on the "Web" page, just change the version on that page.