When using uv venv to create a virtual environment in a Python project, VS Code (Insiders or Stable) was not activating the local environment automatically, even though:
python.terminal.activateEnvironmentwas set totrue.venv/existed at the workspace root- The Python version shown in the terminal (3.12.2) matched the expected version
Despite these, VS Code was defaulting to the global Python interpreter, and modules installed in the uv environment were not found.
Use the command palette (Ctrl+Shift+P) and run:
Python: Select Interpreter
Then:
- If
.venv/bin/pythonis shown, select it. - Otherwise, use
Enter interpreter pathand point to:
${workspaceFolder}/.venv/bin/python
To make the fix persistent and workspace-specific, add this:
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.terminal.activateEnvironment": true
}This ensures VS Code always picks the local .venv, even on new installations or workspaces.
After re-opening the terminal:
which python
# Should point to: ./venv/bin/pythonpip list
# Should show installed modules in the venv- This issue occurs because
uv venvdoesn't always register the environment in a way VS Code recognizes automatically. - Manually setting the interpreter path ensures correct activation and module discovery.
Nice but it doesn't work for me when I try to move from pipenv to uv despite that I deleted .venv (and the Pipfile, Pipefile.lock) and created it agian with uv (uv init; uv venv --python 3.12 --no-managed-python --no-python-downloads). VSC still shows 3.11.13, even when selecting .venv/bin/python manually (solution 1). Adding it to settings (solution 2) doesn't change anything either.
Env: VSC 1.103.0, uv 0.8.8