What if I have multiple Python versions?
You can have multiple simultaneous Python versions installed on Windows, but you will need to provide a separate way of referring to each. To do this we need to make some changes to our environment variables in Windows and create some shortcuts to our Python interpreters.
If you do not care about having multiple Python versions, just uninstall the version that is not Python 3.9.
Environement Variable Setup
- Open the environment variable manager in windows
- Press the windows key, type
environment
into the search box and you should see a result for environment variables
- Press the windows key, type
- Hit enter to open the application
- You should see a window that looks like the one pictured on the left of the image below
- Click the Path Varible in the top section and click the edit button
- A new window should appear that looks like the one pictured on the right of the image above
- Make sure that each Python version is present in this list
- In my image you can see that my accout has two paths, one for version 3.9 and another for 3.10
- If these are NOT present you will need to use the browse button to find the Python folders and add them. The Python folders will be named similarly to mine, but the path will differ.
- Once you have confirmed or added the Paths to your Python installations, hit okay to close the Edit Environment Variable window
- In the main environment variables window, you will need to also change the
PATHEXT
variable - Click the
PATHEXT
variable in the lower window and click edit - Add
;.LNK
to the end of the list of file extensions and click OK. - Click OK to close the main Window
Python Shortcuts
- We now need to locate the installation folder for each Python Version
- You can Google to find the potential paths, or use the information in the Environment Variable manager used in the previous section
- Once you find the folder, locate the file named
python
- Right click the
python
file and select “Create Shortcut” from the menu - Name the shortcut
python[version]
- For example, python 3.8 would have a shortcut named
python38
and python 3.10 would need a shortcut namedpython310
- For example, python 3.8 would have a shortcut named
- Repeat this process for all your Python installations
Running Python
Now that you have shortcuts for all the different python versions, you can use each one separately by using the command python[version]
in your Visual Studio Code terminal. For example, to run a program named test.py
with python 3.10 the command would be python310 test.py
to do the same program with python 3.8 the command would be python38 test.py