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 showFix it fast
Most common cause, 1 of 4A 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).
// .vscode/settings.json: delete a stale line like this one
"python.defaultInterpreterPath": "/usr/bin/python3"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.
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.
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:
- 1A saved interpreter choice outranks the .venv uv created
The Status Bar names another interpreter, and settings.json contains python.defaultInterpreterPath or a pythonProjects entry - 2The integrated terminal is not activated, so python means the system interpreter
The editor uses .venv, but which python in the VS Code terminal prints a path outside the project - 3uv was told to put the environment outside the workspace
There is no .venv folder in the project and UV_PROJECT_ENVIRONMENT prints an absolute path elsewhere - 4A notebook cannot use the .venv because ipykernel is missing
Python 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 syncpython in the VS Code terminal runs the system interpreter, so packages that uv installed are missingThe .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.
grep -nE "defaultInterpreterPath|pythonProjects|defaultEnvManager" .vscode/settings.jsonFix
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.
// .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.
python -c "import sys; print(sys.prefix)"Confirmed by code.visualstudio.com
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.
grep -nE "autoActivationType|activateEnvironment" .vscode/settings.jsonFix
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.
{
"python-envs.terminal.autoActivationType": "command"
}Verify
A fresh terminal prints the project's .venv interpreter, and uv run reports the same one.
uv run python -c "import sys; print(sys.executable)"Confirmed by code.visualstudio.com
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.
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.
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.
ls -d .venv && uv run python -c "import sys; print(sys.prefix)"Confirmed by docs.astral.sh
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.
uv pip show ipykernelFix
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.
uv add --dev ipykernelVerify
The kernel picker shows the .venv and a cell prints the project's interpreter.
import sys; print(sys.executable)Confirmed by docs.astral.sh
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.