VS Code: Change Python version & select correct Interpreter

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
4 min

banner

# VS Code: Change Python version & select correct Interpreter

To change your Python version and select the correct Python interpreter in VS Code:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type python interpreter and click on Python: Select Interpreter.

python select interpreter

  1. A list of versions and Python interpreters is displayed.

select correct interpreter and version

  1. Select the correct version and interpreter.

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.

Selecting an interpreter sets which Python interpreter is used by the Python extension in the workspace (project).

Make sure you have the Python extension by Microsoft installed.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type python.

make sure python extension is installed

  1. Make sure the Python extension by Microsoft is installed and enabled.

# Setting the Python interpreter via the Status Bar

You can also use the status bar to set the Python interpreter and change the Python version:

  1. Open a Python file.

click on python version in status bar

  1. Click on the Python version in the status bar.

  2. Select the correct interpreter.

select correct interpreter

Make sure to open a Python file, otherwise, the Python version won't show in the status bar at the bottom.

# Explicitly specifying the path to the Python interpreter in VS Code

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.

shell
where python

find path to python interpreter windows

On Linux and macOS, use the which python command instead.

shell
which python

find path to python interpreter linux macos

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.

shell
python -c "import sys; print(sys.executable)"

find path to python interpreter

And, here is a screenshot of running the command on Windows.

running custom command on windows

Make note of the complete path to the interpreter.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type python interpreter and click on Python: Select Interpreter.

python select interpreter

  1. Click on Enter interpreter path....

enter interpreter path

  1. Select Find....

select find

  1. Navigate to the Python interpreter on your machine and select it.

# Setting the Default interpreter Path

If you still aren't able to set the correct Python interpreter:

  1. Make note of the complete path to the interpreter as shown in the previous subheading.
  2. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type python path and scroll to the Python: Default interpreter Path setting.

find python default interpreter path setting

  1. Paste the absolute path to the Python interpreter on your machine.

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:

  1. Pressing:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Typing python clear interpreter and clicking on Python: Clear Workspace Interpreter Setting.

python clear interpreter

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.

check if correct interpreter is selected

I used the following code to print the version of the Python interpreter within a module.

main.py
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.

click run button

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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.