VS Code can run your Python script with the wrong interpreter without any obvious warning. The code works in your terminal but fails in the editor, packages you installed seem invisible, and the version number in your error messages never matches the Python you thought you were using. Every one of these mysteries has the same root cause: VS Code is set to a different Python interpreter than the one you expect. This guide shows you how to see which interpreter is selected, how to change it correctly, and how to make the choice stick for a whole project.
Quick Answer
Press Ctrl+Shift+P (or Cmd+Shift+P on macOS), type Python: Select Interpreter, press Enter, and choose the environment you want from the list, for example your project’s .venv or the system Python 3.12. The status bar at the bottom of VS Code then shows the selected version, and new terminals will activate that environment automatically.
Why the Interpreter Choice Matters
An interpreter is the actual python.exe (or python binary) that runs your code. Each installation and each virtual environment carries its own set of installed packages. When VS Code uses the global Python but you installed your packages into a project virtual environment, imports fail with ModuleNotFoundError even though you definitely installed the package. The Run button, the debugger, the linter, and the editor’s IntelliSense all follow the selected interpreter, so one wrong setting produces a whole family of confusing symptoms at once.
If you have ever seen the message covered in our guide to VS Code saying “Python was not found”, you have met the extreme version of this problem, where the selected interpreter does not exist at all.
Step by Step: Select the Interpreter
- Open your project folder in VS Code with File → Open Folder. Interpreter settings are stored per folder, so opening a lone file instead of the folder can hide your environment from the list.
- Open the Command Palette with
Ctrl+Shift+Pand start typingPython: Select Interpreter. Choose the command when it appears. You need the Microsoft Python extension installed for this command to exist. - Read the list carefully. Each entry shows a version and a path. Entries inside your project folder with
.venvin the path are your virtual environments. Entries underAppData\Local\Programs\Pythonor/usr/binare system installs. Pick the environment where you actually installed your packages. - If your environment is missing, use “Enter interpreter path”. Choose the option to enter a path, click Find, and browse to the executable: on Windows it is
.venv\Scripts\python.exeinside your project; on macOS and Linux it is.venv/bin/python. - Verify the choice. The status bar at the bottom now shows the selected version, such as
3.12.4 ('.venv': venv). Open a new terminal withCtrl+`— VS Code should activate the environment automatically, showing(.venv)in the prompt. - Run a test snippet. Create a scratch file with
import sys; print(sys.executable)and run it. The printed path must match the environment you picked. This printout is the ground truth whenever anything later seems off.
Making the Choice Permanent for a Project
When you select an interpreter for an open folder, VS Code saves it in .vscode/settings.json inside that folder as python.defaultInterpreterPath. That is normally what you want: the project remembers its environment. Two practical notes follow from this. First, if you share the project, that path may be wrong on another machine, which is why teams often leave the machine-specific path out of version control. Second, if you ever delete and recreate the .venv in the same location, the saved path stays valid, which is a nice argument for always using the same environment folder name.
The official VS Code documentation on Python environments explains discovery rules for conda, venv, and global installs if your setup is unusual.
When the Terminal and the Run Button Disagree
A classic puzzle: the Run button fails to import a package, yet typing python myscript.py in the integrated terminal works. This happens because the terminal was opened earlier and had an environment activated manually, while the editor setting points elsewhere. Selecting the interpreter properly, then opening a fresh terminal, brings both into line. If you deliberately created the environment from scratch, our walkthrough on creating and activating a virtual environment on Windows 11 shows where the .venv path should appear in the list.
Common Mistakes to Avoid
- Opening a single file instead of the folder. Without the project folder open, VS Code applies workspace defaults and may not even offer your virtual environment.
- Picking the interpreter with the highest version number by habit. The right choice is the environment containing your project’s packages, not necessarily the newest Python.
- Judging by the old terminal. Existing terminals keep whatever environment they already had. Always judge the setting with a newly opened terminal.
- Forgetting the extension. Without Microsoft’s Python extension there is no Select Interpreter command at all, and the status bar shows nothing about Python.
User, Workspace, and Folder Settings: Who Wins?
VS Code reads settings in layers, and knowing the order explains most “I changed it but nothing happened” stories. Your user settings apply everywhere and hold the global default interpreter. Workspace settings apply when you open a project through a workspace file. Folder settings, stored in that folder’s .vscode/settings.json, apply to that project and override the wider layers. When you run Python: Select Interpreter with a folder open, VS Code writes the choice at the folder or workspace level, which is why the setting follows the project around.
Two practical consequences follow. First, if a project keeps launching the “wrong” Python despite your global preference, its folder-level setting is winning — change it in that project rather than fighting the global default. Second, the newer Python extension prefers the python.defaultInterpreterPath setting as the starting hint and remembers your interactive selection from there. If an old python.pythonPath entry appears in any settings file, it is a leftover from very old versions of the extension and can be deleted; current VS Code ignores it, but its presence confuses humans reading the file. Keeping the layers tidy — one deliberate choice per project, no fossils — makes interpreter behaviour boring, which is exactly what you want from infrastructure.
Conclusion
Selecting the interpreter is a ten-second task that quietly controls the Run button, the debugger, and every import your code makes. Use the Command Palette, pick the environment that actually holds your packages, confirm with the status bar and a sys.executable print, and most “works in terminal, fails in VS Code” puzzles disappear permanently.
Frequently Asked Questions
Where does VS Code show the currently selected interpreter?
In the status bar at the bottom of the window, on the right side, once a Python file is open and the Python extension is active. It shows the version and environment type. Clicking that status bar item opens the same interpreter picker as the Command Palette command.
Why is my virtual environment not in the list?
Usually because the project folder is not open, the environment folder has an unusual name or location, or discovery has not refreshed yet. Use Enter interpreter path → Find and browse directly to .venv\Scripts\python.exe on Windows or .venv/bin/python on macOS and Linux.
Does the selected interpreter affect the integrated terminal?
Yes, for terminals opened after the selection. VS Code activates the chosen environment in new integrated terminals automatically. Terminals that were already open keep their previous state, which is why test results can look inconsistent until you open a fresh one.
Can different projects use different interpreters?
Absolutely, and that is the normal setup. The choice is stored per workspace folder, so Project A can use its own .venv with Python 3.11 while Project B uses another with Python 3.12. Switching folders switches the interpreter with them.
What if the status bar shows no Python version at all?
Open a .py file first, since the indicator only appears when the Python extension activates for a Python context. If it still does not appear, confirm the Microsoft Python extension is installed and enabled, and reload the VS Code window from the Command Palette.


Leave a Reply