Last updated: Apr 6, 2024
Reading time·4 min
To change your Python version and select the correct Python interpreter in VS Code:
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.If you use an anaconda distribution, the correct interpreter will have ('base') in its name as shown in the screenshot.
For example, "Python 3.9.13 ('base') ~/anaconda3/bin/python".
Notice that the path to the interpreter on your machine is contained in each option.
Make sure you have the Python extension by Microsoft installed.
Ctrl
+ Shift
+ X
on Windows or Linux.Command
+ Shift
+ X
on macOS.You can also use the status bar to set the Python interpreter and change the Python version:
Click on the Python version in the status bar.
Select the correct interpreter.
Make sure to open a Python file, otherwise, the Python version won't show in the status bar at the bottom.
If you aren't able to set the Python version and interpreter using the previous two approaches or your preferred Python interpreter doesn't show up in the menu, you have to specify the complete path to the interpreter.
Open your terminal and issue the where python
command.
where python
On Linux and macOS, use the which python
command instead.
which python
If you want to get the path to a specific Python version, issue the command
scoped to the specific interpreter, e.g. which python3.11
or
where python 3.11
.
If you aren't able to find the path to the Python interpreter, try issuing the following command.
python -c "import sys; print(sys.executable)"
And, here is a screenshot of running the command on Windows.
Make note of the complete path to the interpreter.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.If you still aren't able to set the correct Python interpreter:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
On Windows, the path might be something similar to:
C:\Users\YOUR_USER\AppData\Local\Programs\Python310\python.exe
Make sure to paste the correct absolute path as shown in the previous subheading.
The python.defaultInterpreterPath
setting is read by the Python extension.
The setting should point to the default Python to use when the extension loads up for the first time.
If you select an interpreter for the workspace, the setting is no longer used.
For example, I can clear my interpreter by:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Then, the Python extension will use the python.defaultInterpreterPath
setting.
If you set your interpreter by using the command palette or by clicking on the
Python version in the status bar at the bottom (as shown previously), then the
python.defaultInterpreterPath
is no longer read by the extension.
I've cleared my selected Python interpreter, so if I click on the Run button, I can see that the correct Python version is printed.
I used the following code to print the version of the Python interpreter within a module.
import sys print(sys.version)
You can click on the Run Python File button in the top right corner to run the code and print the active version of the Python interpreter.
If you get the error message "Linter pylint is not installed", check out my other article:
I've also written a detailed guide on how to change the default terminal in VS Code.
You can learn more about the related topics by checking out the following tutorials: