VS Code keeps its own idea of which Python to use, separate from what your terminal finds on the PATH. When Python “does not work in VS Code” — command not found, the wrong version, or a package that is installed but cannot be imported — it is almost always that the editor’s chosen interpreter and the terminal’s are different. The fix is choosing the interpreter explicitly and letting VS Code activate it in the terminal.
Step 1: pick the interpreter#
Open the command palette (Ctrl+Shift+P, or Cmd+Shift+P on a Mac) and run Python: Select Interpreter. A list appears: every Python VS Code has found, including virtual environments in the workspace. Choose the one you want. The status bar, bottom right, shows the selection.
If the list is empty or missing the one you installed, use Enter interpreter path at the top and point at the executable:
# Find the path from a terminal where Python works
python -c "import sys; print(sys.executable)"
python3 -c "import sys; print(sys.executable)"
where.exe python # Windows
which -a python3 # macOS/Linux
The selection is per workspace, so a different project can use a different interpreter. That is a feature, and it is also why it works in one folder and not another.
Step 2: the terminal#
With an interpreter selected, VS Code activates it in every new integrated terminal — for a virtual environment, it runs the activation script for you; for a plain interpreter, it puts the right folder first on the PATH. Two things must be true:
- The terminal was opened after the interpreter was selected. Close old terminals with the bin icon and open a new one.
- The setting is on:
python.terminal.activateEnvironment(it is on by default).
# In the new terminal, confirm they agree
python -c "import sys; print(sys.executable)"
If that prints the interpreter you selected, everything downstream — pip, imports, running scripts — will work.
Virtual environments#
This is where most confusion lives. You created .venv, installed packages into it, and VS Code cannot import them. VS Code is running a different Python that does not have those packages.
- Select the environment’s interpreter: it appears in the list as
.venvwith a star, or enter the path to.venv/bin/python(.venv\Scripts\python.exeon Windows). - Open a new terminal. The prompt should now show
(.venv). - Run
pip listto confirm the packages are there.
Make the habit explicit by writing it into the workspace, so anyone who opens the project gets the same interpreter:
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
}
Save that as .vscode/settings.json. On Windows, the path ends in Scripts\\python.exe.
The run button, the terminal and the debugger#
Three ways to run a file, and they do not always agree:
| Method | Uses |
|---|---|
| Run button (top right) and F5 | The selected interpreter, always |
Typing python file.py in the terminal |
Whatever python resolves to in that terminal |
Typing py file.py on Windows |
The py launcher’s default, ignoring VS Code entirely |
If the run button works and the terminal does not, the terminal was opened before the selection or activation is off. If the terminal works and the run button does not, the selected interpreter is wrong or broken. The table tells you which knob to turn.
PowerShell blocks the activation script#
On Windows, a red error about “running scripts is disabled on this system” when the terminal opens means PowerShell’s execution policy is blocking Activate.ps1. Fix it once, for your user, from any PowerShell:
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Or switch VS Code’s default terminal to Command Prompt or Git Bash, which do not have the restriction.
“python is not recognized” inside VS Code only#
If a standalone terminal finds Python and VS Code’s terminal does not, VS Code was launched with an older PATH — typically it was open when Python was installed, or it was started from a shortcut that does not read your shell profile. Quit VS Code completely and start it again, ideally from a terminal with code ., so it inherits the terminal’s environment.
The Python extension itself#
If Python: Select Interpreter is not in the command palette, the Python extension from Microsoft is not installed or not activated. Install it, reload the window, and open a .py file, which triggers activation. The Output panel’s Python channel logs discovery and activation and names any error.
Questions people ask#
Why does VS Code have its own interpreter setting at all?
Because projects need different Pythons and different environments, and the editor has to know which one to use for IntelliSense, linting, running and debugging without depending on which terminal happens to be open.
Can I make VS Code create the virtual environment?
Yes: Python: Create Environment in the command palette makes a .venv, installs from requirements.txt, and selects it.
Does this apply to Jupyter notebooks in VS Code?
Notebooks pick a kernel separately, top right of the notebook. Choose the same environment there.
The status bar shows no interpreter.
Open a Python file; the status bar item only appears for Python files. If it still does not, the extension has not activated; check the Output panel.
Where to go next#
- Python virtual environments — the thing the interpreter selector is pointing at.
- ‘python’ is not recognized — the PATH-level version of this problem.
- VS Code setup for beginners — the rest of the editor.