Microsoft/vscode

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

Open

#265 613 ouverte le 8 sept. 2025

Voir sur GitHub
 (0 commentaires) (2 réactions) (1 assigné)TypeScript (10 221 forks)batch import
feature-requestgithelp wanted

Métriques du dépôt

Stars
 (74 848 stars)
Métriques de merge PR
 (Merge moyen 11h 43m) (1 000 PRs mergées en 30 j)

Description

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.

Guide contributeur