Skip to content

Deleting .venv outside VS Code leaves the deleted interpreter selected #1886

Description

Problem: Deleting a workspace virtual environment outside VS Code (for example rm -rf .venv in a terminal) leaves it selected. The status bar keeps showing the deleted .venv, and Run, terminals and Pylance keep pointing at an interpreter that no longer exists until the window is reloaded or environments are refreshed manually.

The venv manager refreshes on changes to **/activate files. VS Code reports a deleted folder only as the folder itself (events for the files in it are dropped), so deleting the whole venv folder never matches.

Environment: Windows 11, VS Code 1.140.0, extension main @ 52f6ace.

Before:

Before: .venv deleted from a terminal, status bar still shows .venv 30 s later

Steps to verify fix:

  1. Open a folder that has a .venv and open a .py file; verify the status bar shows .venv.
  2. Delete the folder from a terminal (rm -rf .venv or rmdir /s /q .venv).
  3. Verify within a few seconds the status bar switches to another interpreter.
  4. Recreate it (python -m venv .venv) and verify the status bar switches back to .venv.
  5. Delete an unrelated folder in the workspace and verify the selection does not change.

Found by Copilot

Activity

  1. vs-code-engineering commented on Oct 6, 2026

    @vs-code-engineering

    Sharing media and context from merged PR #1889 for verification:

    Deleting a virtual environment folder outside VS Code (for example rm -rf .venv) now refreshes the venv manager, so the deleted interpreter is no longer selected. Previously the status bar kept showing it until reload.

    • registerSystemPythonFeatures: a second watcher listens for deletions only (**/*). VS Code reports a deleted folder as the folder alone, so the existing **/activate watcher never fires for it.
    • VenvManager.hasEnvironmentAt: the delete handler triggers the existing debounced refresh only when the deleted path is, or contains, a known venv; other deletions are ignored. The check is one set lookup (about 2.6 µs per deletion whatever the number of venvs), so bulk deletions such as clearing __pycache__ stay cheap.
    • Not changed: venvs outside the workspace folders are not watched, as before.

    Before / after

    Folder with .venv (Python 3.13.15); .venv deleted from outside VS Code.

    Before

    Before: status bar still shows the deleted .venv after 30 s

    After

    After: status bar switches to the global Python within ~3 s

    Validation

    Check Result
    UI scenario on main @ 52f6ace ❌ status bar still shows the deleted .venv after 30 s
    UI scenario with this PR ✅ switches to Python 3.14.8 in ~3 s, 3/3
    npm run lint, npm run compile-tests, npm run unittest ✅ 2545 passing (new tests in main.unit.test.ts)

    Created by Copilot

    Source PR: #1889

  2. added a commit that references this issue on Oct 6, 2026
    7b69d86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-environmentEnvironment, interpreter related issues.bugIssue identified by VS Code Team member as probable bugtriage-neededverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions