Microsoft/vscode

Better integration of pre-commit hooks with Python virtual environments.

Open

#265.613 geöffnet am 8. Sept. 2025

Auf GitHub ansehen
 (0 Kommentare) (2 Reaktionen) (1 zugewiesene Person)TypeScript (10.221 Forks)batch import
feature-requestgithelp wanted

Repository-Metriken

Stars
 (74.848 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 11h 43m) (1.000 gemergte PRs in 30 T)

Beschreibung

Currently, pre-commit hooks inside VS Code cannot find tools installed in a project’s virtual environment unless VS Code itself is launched from within that environment.

Example

  • I have a pre-commit hook configured to run isort.
  • If I open the project directly in VS Code, pre-commit fails because isort cannot be found.
  • If instead I activate the virtual environment in a terminal and then start VS Code with code ., the environment is inherited correctly and pre-commit works.

This makes the workflow inconvenient since developers must remember to always launch VS Code from an activated venv.


Steps to Reproduce

  1. Create a Python project with a virtual environment.
  2. Install isort (or another tool) in the venv.
  3. Add a .pre-commit-config.yaml with a hook that uses the tool.
  4. Open the project in VS Code without starting from the venv.
  5. Run a commit → pre-commit fails with tool not found.

Expected Behavior / Feature Proposal

It would be very useful if VS Code could automatically detect and use the project’s Python virtual environment when running pre-commit hooks.
This way, pre-commit would always work consistently regardless of how VS Code was launched.


Why This Matters

  • Improves developer experience by reducing friction.
  • Makes pre-commit integration more reliable for Python projects.
  • Aligns with how VS Code already handles selecting Python interpreters for debugging and linting.

Contributor Guide