- 1 year ago
Unable to change default python version in windows
Changing the default Python version on Windows can be a bit tricky, especially if you have multiple Python installations. Here are some steps you can follow to change the default Python version:
Check Installed Python Versions:
First, make sure you have multiple Python versions installed on your system. Open a Command Prompt and run the following command:bashpython --version
This will display the currently set default Python version.
Additionally, you can check all installed Python versions by running:
bashpy --list
Update PATH Environment Variable:
The default Python version is determined by the order of entries in thePATH
environment variable. To change the default version, you need to modify thePATH
so that the desired Python version comes first.For example, if you want to use Python 3.9 as the default version, you should add the path to Python 3.9 to the beginning of the
PATH
variable. To do this, follow these steps:- Press
Win + R
, typesysdm.cpl
, and press Enter to open the System Properties window. - Go to the "Advanced" tab, and click on the "Environment Variables" button.
- In the "System variables" section, find the "Path" variable and click on "Edit."
- In the "Edit Environment Variable" window, click on "New" and add the path to Python 3.9 (e.g.,
C:\Python39
) to the top of the list. - Click "OK" to close all the windows.
- Press
Verify the Default Version:
Close and reopen the Command Prompt to apply the changes. Now, when you run:bashpython --version
It should display the version of Python 3.9, assuming you added the correct path.
Use Python Launcher (py.exe) (Optional):
If you have multiple Python versions installed, you can use the Python Launcher (py.exe
) to easily switch between versions on a per-script basis. To run a script with a specific version, use the following command:bashpy -3.9 script.py
This will execute the
script.py
file using Python 3.9.
Remember that modifying the PATH
variable can affect how other applications and scripts work. Be careful when making changes and ensure that the paths you add are correct and point to the desired Python installations.