Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

VS Code keeps another Python instead of the virtual environment uv created

Your error

The Status Bar shows a global Python instead of the project's .venv after uv sync3 more lines it can show

Fix it fast

Most common cause, 1 of 4

A saved interpreter choice outranks the .venv uv created

Run Python: Select Interpreter from the Command Palette and pick the .venv entry (.venv/bin/python on macOS and Linux, .venv\Scripts\python on Windows).

Fix
// .vscode/settings.json: delete a stale line like this one
"python.defaultInterpreterPath": "/usr/bin/python3"
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

VS Code picks an interpreter in a fixed order: a Python project entry, an explicit default manager, the legacy python.defaultInterpreterPath, and only then the workspace .venv uv made. A saved choice, a .venv outside the workspace, an unactivated terminal or a notebook without ipykernel hides it. Run Python: Select Interpreter and pick .venv. Applies to VS Code 1.147, uv 0.13.

  • Applies to VS Code 1.147, Python Environments extension 1.44, uv 0.13.9, Windows, macOS and Linux
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

In a new VS Code terminal, print which interpreter runs and where uv keeps the project environment, then compare both with the Python shown in the Status Bar. A Status Bar entry that is not .venv points to cause 1, a terminal that runs another Python to cause 2, and an environment path outside the folder to cause 3.

Run this first
python -c "import sys; print(sys.executable)"
ls -d .venv; echo "UV_PROJECT_ENVIRONMENT=$UV_PROJECT_ENVIRONMENT"

Then find the line you see in this list and open its fix:

  1. 1A saved interpreter choice outranks the .venv uv createdThe Status Bar names another interpreter, and settings.json contains python.defaultInterpreterPath or a pythonProjects entry
  2. 2The integrated terminal is not activated, so python means the system interpreterThe editor uses .venv, but which python in the VS Code terminal prints a path outside the project
  3. 3uv was told to put the environment outside the workspaceThere is no .venv folder in the project and UV_PROJECT_ENVIRONMENT prints an absolute path elsewhere
  4. 4A notebook cannot use the .venv because ipykernel is missingPython files run in .venv, but a Jupyter notebook in the same folder does not offer it as a kernel or asks for ipykernel

What does the error look like?

  • The Status Bar shows a global Python instead of the project's .venv after uv sync
  • python in the VS Code terminal runs the system interpreter, so packages that uv installed are missing
  • The .venv is not listed when selecting an interpreter (Environment not listed)
  • VS Code requires ipykernel to be present in the project environment.

Cause 1 of 4

A saved interpreter choice outranks the .venv uv created

You seeThe Status Bar names another interpreter, and settings.json contains python.defaultInterpreterPath or a pythonProjects entry

Check

When VS Code is not using the uv virtual environment even though .venv exists, check the selection order in its documentation: a pythonProjects entry comes first, then an explicitly set defaultEnvManager, then the legacy python.defaultInterpreterPath, and auto-discovery of a workspace .venv comes last. Any older choice therefore keeps winning after uv sync creates the environment.

Check
grep -nE "defaultInterpreterPath|pythonProjects|defaultEnvManager" .vscode/settings.json

Fix

Run Python: Select Interpreter from the Command Palette and pick the .venv entry (.venv/bin/python on macOS and Linux, .venv\Scripts\python on Windows). A manual pick updates pythonProjects. Remove a leftover python.defaultInterpreterPath that points elsewhere so it cannot return as a fallback.

Fix
// .vscode/settings.json: delete a stale line like this one
"python.defaultInterpreterPath": "/usr/bin/python3"

Verify

The Status Bar shows the .venv, and a script run from VS Code prints a prefix inside the project.

Verify
python -c "import sys; print(sys.prefix)"

Confirmed by code.visualstudio.com

Did this fix it?

Cause 2 of 4

The integrated terminal is not activated, so python means the system interpreter

You seeThe editor uses .venv, but which python in the VS Code terminal prints a path outside the project

Check

Terminal activation is a separate step. The Python Environments extension activates the selected environment through python-envs.terminal.autoActivationType, which can be command, shellStartup or off, and a changed value only applies to terminals opened afterwards. With off, or in a terminal that was already open before the change, python resolves through PATH as usual.

Check
grep -nE "autoActivationType|activateEnvironment" .vscode/settings.json

Fix

Set activation to command (or shellStartup) and open a new terminal. Commands started with uv run need no activation at all, because uv finds the .venv in the working directory or a parent directory.

Fix
{
  "python-envs.terminal.autoActivationType": "command"
}

Verify

A fresh terminal prints the project's .venv interpreter, and uv run reports the same one.

Verify
uv run python -c "import sys; print(sys.executable)"

Confirmed by code.visualstudio.com

Did this fix it?

Cause 3 of 4

uv was told to put the environment outside the workspace

You seeThere is no .venv folder in the project and UV_PROJECT_ENVIRONMENT prints an absolute path elsewhere

Check

uv names the project environment .venv unless UV_PROJECT_ENVIRONMENT says otherwise, and an absolute value is used exactly as given. VS Code searches the workspace with the glob ./**/.venv by default, so an environment kept in another directory never appears in the list.

Check
echo "$UV_PROJECT_ENVIRONMENT"

Fix

Either unset the variable and let uv sync build .venv inside the project, or add the folder that holds the environment to python-envs.globalSearchPaths in your user settings (absolute paths only) and refresh the environment managers.

Fix
unset UV_PROJECT_ENVIRONMENT
uv sync
# or, in user settings.json:
# "python-envs.globalSearchPaths": ["/home/dev/envs"]

Verify

After Python Environments: Refresh All Environment Managers, the environment appears in the interpreter list.

Verify
ls -d .venv && uv run python -c "import sys; print(sys.prefix)"

Confirmed by docs.astral.sh

Did this fix it?

Cause 4 of 4

A notebook cannot use the .venv because ipykernel is missing

You seePython files run in .venv, but a Jupyter notebook in the same folder does not offer it as a kernel or asks for ipykernel

Check

VS Code notebooks still discover environments through the older Python extension API, so their kernel list can differ from the Environment Managers view. The uv guide adds that VS Code requires ipykernel inside the project environment and has you add it yourself as a development dependency.

Check
uv pip show ipykernel

Fix

Add ipykernel as a development dependency, reopen the notebook, choose Select Kernel, then Python Environments, then the .venv. If the notebook uses %pip, create the environment with uv venv --seed so pip exists inside it.

Fix
uv add --dev ipykernel

Verify

The kernel picker shows the .venv and a cell prints the project's interpreter.

Verify
import sys; print(sys.executable)

Confirmed by docs.astral.sh

Did this fix it?

How do I stop it coming back?

  • Keep python.defaultInterpreterPath out of shared .vscode/settings.json; let each developer select the .venv once.
  • Add uv add --dev ipykernel to the project template if the team works in notebooks.
  • Use UV_PROJECT_ENVIRONMENT only in CI or containers, not on developer machines where VS Code must find .venv.
  • Run project commands as uv run ... so they use .venv whatever the terminal state.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.