Repository navigation
Specify pyright environment for pre-commit #7423
Replies: 2 comments
|
Configure the environment Pyright analyzes, separately from the isolated environment pre-commit uses to run its hook. For a project environment at {
"venvPath": ".",
"venv": ".venv"
}
Alternatively, pass an interpreter explicitly through your existing Pyright hook's arguments: # POSIX, within the existing hook definition
args: [--pythonpath, .venv/bin/python]On Windows, the interpreter is typically Add References: venv/venvPath settings, CLI interpreter selection. These environment settings concern Pyright's CLI; Pylance uses VS Code's selected interpreter instead. |
|
Pre-commit creates an isolated environment for hooks, so activating your project's virtual environment does not necessarily make it available to Pyright. You can explicitly configure the environment in your pyproject.toml: [tool.pyright] Replace .venv with your virtual environment's directory name. This allows Pyright to resolve dependencies from the correct environment. See the [Pyright import resolution documentation](https://github.com/microsoft/pyright/blob/main/docs/import-resolution.md). |
Uh oh!
There was an error while loading. Please reload this page.
Pre-commit uses the system python environment instead of the selected python environment though (even if you activate the virtual environment before running pre-commit). How do you have pyright run in the correct environment when using pre-commit?
All reactions