Under the
Viewmenu selectCommand Palette... F1(or press F1 key).Type
Python: Select Interpreter.Choose which Python version to use by default [1].
[1] You can safely disregard the "Recommended" hint, which is usually the bare bones system one, without access to your custom packages.
Answer from Natsfan on Stack OverflowUnder the
Viewmenu selectCommand Palette... F1(or press F1 key).Type
Python: Select Interpreter.Choose which Python version to use by default [1].
[1] You can safely disregard the "Recommended" hint, which is usually the bare bones system one, without access to your custom packages.
Several of the answers here explain good approaches, but below are my top 2 recommendations.
1) Bottom Screen Navigation (ease of access)
- I find this the quickest approach; however, it isn't always available for first-time users. If you're already using Python in VS Code, this is usually the easiest way to reach the Python: Select Interpreter menu. On the bottom left of your screen, look for "Python X.X.X". This is the currently detected/configured version of Python for your project, and clicking it brings you to the interpreter menu to change the Python version you're using. At the time of writing, I was using Python 3.9.1 as seen in the snippet below:

2) Command Palette
- As @jmh denoted in his answer, you can also use the 'View' tab to navigate to the Command Palette. In the Command Palette, search for Python: Select Interpreter to bring about the same menu denoted above.
If you're still having issues, there's also a VS Code Getting Started guide that walks you through setting up Virtual Environments and/or choosing different interpreters for Python that support the desired language: https://code.visualstudio.com/docs/python/python-tutorial
Happy coding!
Changing Python Interpreter Path setting not working
Need to select Python interpreter in VS code
Issue with the interpreter in Visual Studio Code
Virtual Environments in vscode, Change python path in Windows - Python - Code with Mosh Forum
Videos
I installed Python 3.11 today and changed the Python: Default Interpreter Path setting in VS Code. But when I run a Python file, VS Code still uses the old Python 3.10 interpreter.
Notes:
-
I'm using Windows 11.
-
In the terminal,
python --versionshows 3.11 only, as I had corrected the Python directory in the Environment Path globally.
I am using a match case statement in my Python code. It works when I run from the terminal using the following command in the terminal.
python3 main.py
But when I right-click on main.py and click on "run code". It still uses an older interpreter and gives an error of invalid syntax.
My question is how to configure Visual Studio code to run Python3 by default?
Maybe Virtual Studio Code does not use the same shell that you're using with iTerm2? According to the docs on the integrated terminal, the shell that is being used is the one which is set by the $SHELL environment variable. Inspect it with:
echo $SHELL
Furthermore, which scans your $PATH for an executable and return the first one found. So compare your settings there, too:
echo $PATH
If that is the issue, you can change $PATH, so it will find the python in /Users/anders/anaconda3/bin instead of /usr/bin.
Finally, it might help you to set an alias for python in the Visual Studio Code integrated terminal. You can set that up with:
$ alias python
bash: alias: python: not found
$ alias python=/Users/anders/anaconda3/bin/python
$ alias python
alias python='/Users/anders/anaconda3/bin/python'
(which might still show the other path, but if you run python, you'll get the one from the alias.)
I found a way to reset VS Code such that it works again.
Step one: Reset your $PATH variable -> this is temporary because all sorts of funky stuff starts to happen if you reset this:
$cd #go to home directory
$nano .bash_profile
# while in nano:
\export PATH="[path to anaconda python3]"
# save and exit
# reset .bash_profile
$. .bash_profile
now we need to set PATH to what it was, but nanowill no longer work, so we put following into the terminal:
$usr/bin/nano ~/.bash_profile
delete the line "\export PATH="[path to anaconda python3]""
# reset .bash_profile again
$. .bash_profile
Now if you open up VS Code (or a new terminal in VS Code), it should work!