For me it worked by changing the final step in the selection process:
The start is as usual:
Command Palette> Python: Select Interpreter+ Enter interpreter path
but then, not picking the option
Find... Browse your file system to find a Python interpreter(which opens a file explorer to select the interpreter)
but instead
- directly enter the full path in the text field and press Enter.
In theory, both should have the same effect, but for my case they did not. (I had tried reloading the window, restarting vscode, adding the venv to the known venv folders in the workspace settings, even recreating the venv in case something went wrong there, but none of these options worked.)
Answer from user12378033 on Stack OverflowFor me it worked by changing the final step in the selection process:
The start is as usual:
Command Palette> Python: Select Interpreter+ Enter interpreter path
but then, not picking the option
Find... Browse your file system to find a Python interpreter(which opens a file explorer to select the interpreter)
but instead
- directly enter the full path in the text field and press Enter.
In theory, both should have the same effect, but for my case they did not. (I had tried reloading the window, restarting vscode, adding the venv to the known venv folders in the workspace settings, even recreating the venv in case something went wrong there, but none of these options worked.)
For those who have tried these steps:
- select different interpreter
- reboot VScode
- reinstall VScode Python extension and delete its folders
and have achieved nothing.
Probably you are working in the workspace and not in folder. You may have set interpreter at workspace level, which can't be used in one of the folders of the workspace. Try opening your folder separately from the workspace and select interpreter you want. This worked for me.
python3 - Cant change python interpreter in Visual Studio Code on Mac - Unix & Linux Stack Exchange
Python interpreter settings ignored if VS Code is launched from an activated environment
Can't set Python interpreter
visual studio code - Select Python interpreter does not work in VSCode - Python programs still use the old interpreter - Stack Overflow
Videos
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!
I just reloaded the Python extension which you will see when you go to VSCode and the "Python extension"; the "reload required" button will be there; just click and then check the "Python interpreter" in the "view" again; it will resolve the current issue which you are facing.
The reason for this, at least on Macs, is that the python/python3/python3.9 inside virtual environments is a symlink to the system interpreter in e.g. /opt/homebrew/bin/python3 and VSCode follows the symlink.
So the path for relative imports and all the packages in your virtual environment is now /opt/homebrew/bin instead of ./venv/bin, and so VSCode can't resolve any of the imports from your venv unless they happen to also be installed in /opt/homebrew/bin. This means you lose the "jump to definition" and similar functionality, "run this code" doesn't work, linters can't provide any kind of import-related feedback, etc.
A solution that works is to copy the python binary into the venv, rather than use symlinks. You can do this after you create the venv.
python -m venv venv
rm venv/bin/python venv/bin/python3 venv/bin/python3.9
cp /opt/homebrew/bin/python3.9 venv/bin/
ln -s venv/bin/python3.9 venv/bin/python
ln -s venv/bin/python3.9 venv/bin/python3
source venv/bin/activate
pip install -r your_requirements_file.txt
Then set the python interpreter in VSCode to venv/bin/python3.9 and everything will work.
This was reported but a fix didn't garner enough votes to be implemented.
https://github.com/microsoft/vscode-python/issues/13603
Of course, change the paths and python versions in the code above as needed.
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.
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!
All you have to do is press ctrl+shift+p or ⌘+⇧+p Then will get a search bar kinda thing on top of the screen.
Then type the following command:
> python: select interpreter

You will be provided with options. Select the one you want to use.
At the bottom of the MS Code screen is an info bar that lets you know what line, col, text encoding, etc... It also shows the python interpreter you are accessing.
If you click on the text for the version of python that is running, it will open a list of available interpreters on your system. If 2.7 is in your path, you can select it.