I want to alias python3 to python on windows. I have already removed the alias for the microsoft store as described in this answer. However python3 is still not a known alias. How to I fix this?
- 483
5 Answers
I want to alias
python3topythonon Windows.
You haven't mentioned what release of Python you are using (e.g. "vanilla" Python, Anaconda, SciPy, etc.), but if I am not misunderstanding, this likely shouldn't be necessary. For Windows versions of Python (i.e. not WSL), python3 is not typically a standard alias. That is, the Python 3.x executable is usually just python (python.exe).
Be aware that python.exe should be in a folder listed in your Windows Path if you want to access it as just python. You can find a refresher on editing Windows Path variables here.
If you meant the reverse (i.e. you want to run Python 3.x with python3), then there are at least a few possible approaches (each item below is a separate option):
Make symbolic link called
python3.exeto your preferred copy of Python 3.x with mklink:mklink "C:\path\to\symlink\python3.exe" "C:\path\to\Python3\python.exe"Copy the
python.exefile in your preferred installation of Python 3.x and rename the copied executablepython3.exe.If you aren't set on specifically using
python3and have the Python Launcher for Windows (py.exe) installed which comes with "vanilla" Python from python.org, you can use:# Use the "default" installation of Python 3.x, # as detected by the Python Launcher for Windows.py 3
or:
# Use a specific version of Python 3.x if you have more # than one version installed, outside of a virtual environment.py 3.8
Create a Windows batch file called
python3.batwith the following information:ex. python3.bat
C:\path\to\Python3\python.exe %*You can also alias Python Launcher for Windows (
py.exe) calls in a similar manner inpython3.bate.g.:ex. python3.bat
py 3 %*or:
ex. python3.bat
py 3.8 %*
With all the options above, any "python3" file you wish to access from the command line (i.e. any symbolic link, a renamed executable copy, py.exe or python3.bat) must be in a folder located in your Windows Path.
Notes
These options obviously do not include any option to "alias"
python.exeat the command line (e.g. via doskey macros, as mentioned in the comments, or possibly via actual alias commands specific to a given terminal). It also ignores the possibility that some distributions of Python could (theoretically) already come with apython3alias.Creating a symbolic link with
mklinkon Windows may require administrative privileges on versions of Windows earlier than some early releases of Windows 10.When creating a symbolic link, be certain to include the file extension (
.exe). This is not optional if you want the link to work correctly.It is likely best to leave any renamed executable copy (option 2) in the same folder as the original
python.exe.
- 109
- 18,227
If you are using the Windows PowerShell and not the command prompt, you can use the following code:
Set-Alias -Name python3 -Value python
or use the following code:
Set-Alias -Name python3 -Value "C:\Python39\python.exe"
Note that this is a temporary Alias for the current session, to make it permanent; you have to copy the above command into an empty text file and name it Profile.ps1 file and copy it to one of the following folders:
if you are using PowerShell 7:
{My Documents Folder}/PowerShell
if you are using Windows PowerShell which comes by default in Windows 10:
{My Documents Folder}/WindowsPowerShell
or inside the installation folder of PowerShell, which can be figured out by:
cd $PSHOME\
- 163
- 231
If your python 3.x is already in your PATH and you've already deleted any previous python3 versions from your machine (and PATH), you just need to run:
mklink "C:\path\to\Python3\python3.exe" "C:\path\to\Python3\python.exe".
If you're running multiple versions of python3, you can set the symlink to whatever you want:
mklink "C:\path\to\Python3\pythonXYZ.exe" "C:\path\to\Python3\python.exe".
Restart cmd prompt and python3 --version or pythonXYZ --version will print your linked version
- 131
If you are still wondering how to do it, Here is one workaround!
Create a PowerShell file named python3.ps1 and inside that just type python and save it anywhere you like.
Copy that path and add that path to the Environment path.
Now you are ready to go!
Just type python3 and it runs python.
you can also use the python command to use python.
- 21
- 4
For people ending up here while using powershell, this is another way to create symlinks.
Caveat: Requires Admin rights or group policy that allows this on normal mortal users
- Open Admin / Link creation capable powershell terminal
- Run
$venv=((get-command python).source | Get-ItemProperty).DirectoryName;New-Item -Path $venv -Name "python3.exe" -Value "$venv\python.exe" -ItemType SymbolicLink
If you work no a virtual environment, run this first:
.\.venv\Scripts\Activate.ps1
- 105