Duplicating the Python 3 executable python.exe
and renaming it to python3.exe
suggested in another answer is a terrible idea, please don't do it, because you would have to repeat it every time you upgrade Python to a newer version and it's likely that you'll forget it and you'll be surprised that your Python is broken after the upgrade.
I suggest the following simple setup.
Solution: Symbolic Link python3.exe
Just create a symbolic link named python3.exe
in a directory which is in your PATH
environment variable (but which is not under the Python 3 installation directory) pointing to the Python 3 executable python3/python.exe
. The symbolic link stays there and keeps pointing to the correct executable even if you upgrade the Python (since it's outside the Python 3 installation directory, it's not affected even when the whole directory of an outdated Python is deleted and a new Python is placed there).
It's very easy to prepare:
- Execute an elevated Powershell Core (
pwsh.exe
), Powershell (powershell.exe
), or Windows command shell (cmd.exe
)
- Decide where you want to create the symbolic link:
- Pick a directory already in your
PATH
environment variable (use echo $env:PATH
in Powershell or echo %PATH%
in cmd.exe
to print the variable contents)
- Add any directory you like to the
PATH
variable (see below)
- Navigate to the directory you chose in the previous step and create there a symbolic link named
python3.exe
pointing to the Python 3 executable (the target
parameter), both paths may be absolute or relative:
Now, if you execute python3
or python3.exe
from any directory, Windows searches it in the current directory and then all directories in your PATH
environment variable. It finds the symbolic link you have created which "redirects" it to the Python 3 executable and Windows executes it.
Notes
Which version executes python
command?
What Python version is being executed by the command python
when both Python 2 and 3 are installed, depends on the order of Python directories in the PATH
environment variable.
When you execute a command and it's not being found in the current working directory, Windows iterates through all directories in the PATH
variable while keeping the order as they're listed there and executes the first executable whose name matches the command (and it stops the searching).
So, when your PATH
variable contains Python installation directories in the order c:\dev\python2\;c:\dev\python3;...
, then the python
command executes python.exe
in the c:\dev\python2\
because it was found first.
The order depends on the order in which you have installed both Python versions. Each installation adds (if you check that option) its instalation directory at the beggining of PATH
, so the most recently installed version will be executed when you execute just python
. But you can reorder them manually, of course.
pip
There's no issue with pip, because there's already an executable named pip3.exe
that's located in a directory automatically added to the PATH
during the installation by Python (<installation-root>\Scripts
, so just use pip3
for the Python 3's pip and pip
/pip2
for the Python 2's pip.
Editing Environment Variables
- Open the Windows' About dialog by pressing Win + Pause/Break or right-clicking This PC and selecting Properties
- Open the System Properties dialog by clicking the link Advanced system settings on the right side of the Settings dialog
- Open the Environment Variables dialog by clicking the button Environment Variables... at the bottom of the System Properties dialog
- Here, you can manage user variables and if you have the admin rights then also system variables
git-bash
andbash
are 2 absolutely different programs. also, have a look at this question – Corrinecorrinnepython3
and not justpython
? – Heliometerpython3.exe
in theC:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\Scripts\
folder ? Try running the exact name instead – Corrinecorrinnepython3
on some platforms, where the default (python
) is the old python 2. OS X, for example. – Heliometer