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!
VScode using the wrong version of python for virtual environments
windows - How to specify the python version for VSCode virtual environment, when I have multiple python versions intalled? - Stack Overflow
How can I set up a virtual environment for Python in Visual Studio Code? - Stack Overflow
How do you get Visual Studio Code to use different Python interpreter? - Stack Overflow
Videos
edit: solved
My python is fully updated, 3.11.1, but if I create a VN in it the venv goes to the python 3.9.13 interpreter, which is a problem. Meaning if I select the correct 3.11.1 interpreter, it doesn't use the VN. Without a VN everything runs in 3.11.1. How do I fix this so I can use the correct interpreter?
Picture to clarify
I have been using Visual Studio Code for a while now and found an another way to show virtual environments in Visual Studio Code.
Go to the parent folder in which
venvis there through a command prompt.Type
code .and Enter. [It is working on both Windows and Linux for me.]That should also show the virtual environments present in that folder.
Original Answer
I almost run into same problem every time I am working on Visual Studio Code using venv. I follow the below steps:
Go to menu File โ Preferences โ Settings.
Click on Workspace settings.
Under Files:Association, in the JSON: Schemas section, you will find Edit in settings.json. Click on that.
Update
"python.defaultInterpreterPath": "Your_venv_path/bin/python"under workspace settings. (For Windows): Update"python.defaultInterpreterPath": "Your_venv_path\Scripts\python.exe"under workspace settings.Restart Visual Studio Code in case if it still doesn't show your venv.
Note: Use python.pythonPath instead of python.defaultInterpreterPath for older versions.
With a newer Visual Studio Code version it's quite simple.
Open Visual Studio Code in your project's folder.
Then open Python Terminal (Ctrl + Shift + P: Python: Create Terminal)
In the terminal:
python -m venv venv
You'll then see the following dialog:

Click Yes; and your venv is ready to go.
Open a new terminal within VSCode Ctrl + Shift + P and you'll see that venv is getting picked up; e.g.: (venv) ...
You can now instal packages as usual, e.g., pip install sklearn
To keep track of what is installed: pip freeze > requirements.txt
For the older versions of VSCode you may also need to do the following:
Then Python: Select Interpreter (via Ctrl + Shift + P)
And select the option (in my case towards the bottom)
Python 3.7 (venv)
./venv/Scripts/python.exe
If you see
Activate.ps1 is not digitally signed. You cannot run this script on the current system.
you'll need to do the following: https://stackoverflow.com/a/18713789/2705777
For more information see: Global, virtual, and conda environments
Installing Modules
Ctrl + Shift + P and Terminal: Create New Integrated Terminal
from the terminal
Windows: .\.venv\Scripts\activate
Linux: ./.venv/bin/activate
You can now instal packages as usual, e.g., pip install sklearn.
For Jupyter, you need to do more - Jupyter notebooks in Visual Studio Code does not use the active virtual environment
For choosing interpreter, press ctrl + p and then type >Python: Select Interpreter (don't forget the > character! if it doesn't show up, make sure you have installed python extension on your vs code) and select one of the options. It will show you available interpreters (virtual environments + the global environment) to choose.
If you want to change version of python you are using, you must first create a virtual environment with desired version of python and then choose it as your interpreter. (I recommend to create it in .venv directory in the root directory of your project)
This answer will help you with that.
Open command pallete with F1 (on Windows) and type Python: Select Interpreter.
Hi, i ve got maybe a dumb question, but i can t find any informations how to upgrade my python version, besides the Indian guys trying to explain how to change the interpret in Vscode.
I ve got Linux mint and python 3.10. I want to use python 3.12 in Vscode. But Vscode doesn't offer me 3.12. sudo apt-get upgrade didn't help. I want to use 3.12 in a new venv, but I have no clue how to get it. A link or an explanation for dummies would be fine. Thx in advance!
Hi Guys, I'm a total newbie to Python. But I have to work with two different Python versions as one of my new projects require an older version of Python. I am thinking to install this older version (v3.10) inside a virtual environment and run my project with it. But not sure how to do it.
These are the steps I followed so far:
-
installed Python v3.12 in my PC (using Windows)
-
installed VS code
-
created venv with 'py -m venv .venv '
-
activated venv with '.venv\Scripts\activate.bat '
-
now I want to install python v3.10 in .venv. But when I ran 'py -m pip install "python==3.10.13"' it gives an error saying:
"Could not find a version that satisfies the requirement python==3.10.13 (from versions: none). No matching distribution found for python==3.10.13"
What am I doing wrong in here? am I missing anything? I looked up a video about 'PYENV' but would like to try this way. Any help much appreciated!!
Does running Python this way slow down the run times significantly?
thanks
I've been trying to switch my python version from 2.7.16 to 3.8.2 but it doesn't seem to work.
When I open the command palette I select the 3.8.2 option which is the global version. However, when I run this command, "python --version" it tells me I am using the 2.7.16 version. Is there a way to remedy this? I've tried reinstalling VSC and nothing helps. Even changing the Python>Terminal: Extensions in settings doesn't do anything.