Skip to content

Instantly share code, notes, and snippets.

@danielrosehill
Created April 29, 2025 18:54
Show Gist options
  • Select an option

  • Save danielrosehill/a87111cb5f00d5223fb46eba23371b37 to your computer and use it in GitHub Desktop.

Select an option

Save danielrosehill/a87111cb5f00d5223fb46eba23371b37 to your computer and use it in GitHub Desktop.
How to get UV Python environments to auto-activate in VS Code (Insiders) - OS: Ubuntu Linux

Fix: Python Virtual Environment Not Auto-Activating in VS Code (with uv venv)

Problem

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.activateEnvironment was set to true
  • .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.


βœ… Solution

1. Manually select the interpreter in VS Code

Use the command palette (Ctrl+Shift+P) and run:

Python: Select Interpreter

Then:

  • If .venv/bin/python is shown, select it.
  • Otherwise, use Enter interpreter path and point to:
${workspaceFolder}/.venv/bin/python

2. Set default interpreter in .vscode/settings.json

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.


3. Verify

After re-opening the terminal:

which python
# Should point to: ./venv/bin/python
pip list
# Should show installed modules in the venv

πŸ“ Notes

  • This issue occurs because uv venv doesn't always register the environment in a way VS Code recognizes automatically.
  • Manually setting the interpreter path ensures correct activation and module discovery.
@chr7

chr7 commented Aug 9, 2025 •

Copy link
Copy Markdown

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

@chr7

chr7 commented Aug 9, 2025

Copy link
Copy Markdown

Ok, now I got it activated in the terminal but VSC itself still doesn't use it:

  • in the terminal: python -V returns Python 3.12.11
  • VSC itself still shows 3.11.13 (./.venv/bin/python) in the lower right corner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment