One nice solution to this problem is to use pipx. pipx essentially provides a middle ground between installing nothing to the global python installation and installing everything to the global python installation. pipx is installed into the global python installation and then you use pipx to (1) install (and manage) python-based command line tools (such as pre-commit) within isolated virtual environments and (2) expose those command line tools to the global terminal command namespace. The workflow in this case is:

  1. python -m pip install --user pipx to install pipx to the global python.
  2. pipx ensurepath to make sure path is setup correctly.
  3. pipx install pre-commit
  4. pre-commit install in the git repo of interest
  5. set up .pre-commit-config.yaml in the git repo of interest
  6. Now git commands should work using pre-commit (which uses the pre-commit installed by pipx) on the repo of interest, whether or not the virtual environment is activated.
Answer from Jagerber48 on Stack Overflow
🌐
pre-commit
pre-commit.com
pre-commit
The installed package will provide an executable that will match the entry – usually through console_scripts or scripts in setup.py. This language also supports additional_dependencies so it can be used with local hooks. The specified dependencies will be appended to the pip install command. Support: python hooks work without any system-level dependencies.
🌐
PyPI
pypi.org › project › pre-commit
pre-commit · PyPI
A framework for managing and maintaining multi-language pre-commit hooks. ... Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
      » pip install pre-commit
    
Published   Apr 21, 2026
Version   4.6.0
Discussions

What are your favourite pre-commit hooks and why?
You may fancy me mad, but this is my standard python pre-commit stack: end-of-file-fixer trailing-whitespace fix-byte-order-marker mixed-line-ending name-tests-test no-commit-to-branch autoflake args: [ "--in-place", "--remove-unused-variables", "--remove-all-unused-imports" ] isort black cspell doc8 args: [ "--max-line-length", "112", "--file-encoding", "utf-8" ] flake8 additional_dependencies: [ flake8-pytest-style, flake8-bugbear, flake8-comprehensions, flake8-print, darglint ] bandit pylint More on reddit.com
🌐 r/Python
83
120
April 24, 2024
pyenv - Pre-commit not finding python packages - Stack Overflow
Im using pyenv to support having different versions of python. In a project using python 3.7 I also want linting with pre-commit to run when doing code changes. But when the lint rules run, pre-com... More on stackoverflow.com
🌐 stackoverflow.com
When to use pre-commit hook vs GitHub actions?
You should be using them both. Run pre-commit locally to run checks before committing to your local GitHub repository. Then run GitHub actions when you push and/or create a pull request to the remote repository on GitHub. I use tox to build Python projects with GitHub actions so that the entire build process can be checked across platforms. pre-commit doesn’t do that for me but it still does a lot to my code beforehand so this is why I use both. If the project builds successfully with GitHub actions using tox and all tests pass then I allow the pull request to be approved for merging. If anything fails it’s time to refactor the code and resubmit. More on reddit.com
🌐 r/Python
21
63
October 26, 2023
pre-commit vs pre-push vs CI/CD for linting and formatting?

I’d make it part of merge checks.

Can’t merge unless all the requirements are OK, if formatting/linting are requirements then it’s nice to see failed checks and know what requires fixing.

More on reddit.com
🌐 r/devops
45
80
November 7, 2022
🌐
Medium
medium.com › internet-of-technology › beautify-your-python-code-with-pre-commit-linters-a-step-by-step-guide-d63604d6120b
Pre-commit for Python | Internet of Technology
August 13, 2024 - · Setting up Pre-commit For Python ∘ 1. Install the Pre-commit Linter ∘ 2. Install Python Packages ∘ 3. Add and Update Your Pre-commit Configuration ∘ 4. Install the Git Hook Scripts ∘ 5. Test it · Before And After · Final Thoughts ·
🌐
Towards Data Science
towardsdatascience.com › home › latest › pre-commit & git hooks: automate high code quality
Pre-Commit & Git Hooks: Automate High Code Quality | Towards Data Science
January 16, 2025 - Pre-commit is a useful Python package that improves your git hook workflow and simplifies your scripts. It is designed to keep the quality of your software high and remove the risk of bugs by automating your code-checking process.
🌐
Y-sunflower
y-sunflower.github.io › python-packaging-essentials › blog › workflow › pre-commit.html
9 Pre-commit Hooks – Python Packaging Essentials
Now try editing a Python file (add spaces at the end of the file or change the formatting of something). Then try committing it: git add .pre-commit-config.yaml git commit -m "Test pre-commit"
Find elsewhere
🌐
Hotosm
docs.hotosm.org › dev-guide › repo-management › pre-commit
Pre-Commit - HOTOSM Docs
Pre-commit is a package to automate the setup. After config, issues such as syntax errors and security flaws are picked up. Used mostly for formatting and linting. Linting is checking code against a set of formatting rules and for syntax errors. Pre-commit is a Python tool for simplifying and ...
🌐
GitHub
github.com › pre-commit › pre-commit
GitHub - pre-commit/pre-commit: A framework for managing and maintaining multi-language pre-commit hooks. · GitHub
A framework for managing and maintaining multi-language pre-commit hooks. - pre-commit/pre-commit
Starred by 15.3K users
Forked by 965 users
Languages   Python 97.4% | R 2.0% | Shell 0.5% | Dockerfile 0.1% | Lua 0.0% | Ruby 0.0%
🌐
Poetry
python-poetry.org › docs › pre-commit-hooks
pre-commit hooks | Documentation | Poetry - Python dependency management and packaging made easy
pre-commit hooks pre-commit is a framework for building and running git hooks. See the official documentation for more information: pre-commit.com This document provides a list of available pre-commit hooks provided by Poetry. Note If you specify the args: for a hook in your .pre-commit-co...
🌐
Medium
medium.com › @anton-k. › how-to-set-up-pre-commit-hooks-with-python-2b512290436
How to set up pre-commit hooks with Python? | by Anton K | Medium
April 26, 2022 - Pre-commit is a Python package that lets you run some scripts upon some commit stages. Default ones are commit, push, merge-commit , etc.
🌐
DEV Community
dev.to › techishdeep › maximize-your-python-efficiency-with-pre-commit-a-complete-but-concise-guide-39a5
The Power of Pre-Commit for Python Developers: Tips and Best Practices - DEV Community
May 1, 2023 - You can do this by adding a .pre-commit-config.yaml file to the root of your project. Define precommit hooks: Now, you can define the hooks that precommit will run. For example, you can add a hook to format your code using black. You can also add a hook to lint your code using a tool flake8 . Here's an example of how to define a precommit hook for these tasks: repos: - repo: https://github.com/psf/black rev: 21.7b0 hooks: - id: black language_version: python3.8 - repo: https://github.com/PyCQA/flake8 rev: 3.9.2 hooks: - id: flake8
🌐
Stefanie Molin
stefaniemolin.com › articles › devx › pre-commit › setup-guide
How to Set Up Pre-Commit Hooks | Stefanie Molin
December 7, 2025 - In this tutorial, we will be using the pre-commit Python package to set up our hooks. This does not mean that we can only use pre-commit with Python projects: we can use it in any project as long as there is a Python interpreter available on the machine.
🌐
PyDevTools
pydevtools.com › handbook › how-to › how-to-set-up-pre-commit-hooks-for-a-python-project
How to set up pre-commit hooks for a Python project | pydevtools
2 days ago - - repo: https://github.com/pre-commit/mirrors-mypy rev: v2.0.0 hooks: - id: mypy additional_dependencies: [] ... mypy 2.0 changed several defaults that may surface new errors in code that passed under 1.x. See the mypy reference page for details. mypy 2.0 also requires Python 3.10 or newer as both a runtime and a target. Add any type stub packages your project needs to additional_dependencies.
🌐
PyPI
pypi.org › project › pyproject-pre-commit
pyproject-pre-commit · PyPI
If you're not sure which to choose, learn more about installing packages. pyproject_pre_commit-0.6.1.tar.gz (125.7 kB view details) ... Filter files by name, interpreter, ABI, and platform. If you're not sure about the file name format, learn more about wheel file names. ... Details for the file pyproject_pre_commit-0.6.1.tar.gz. ... Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
      » pip install pyproject-pre-commit
    
Published   Feb 07, 2026
Version   0.6.1
🌐
Talk Python To Me
talkpython.fm › episodes › show › 482 › pre-commit-hooks-for-python-devs
Episode #482 - Pre-commit Hooks for Python Devs | Talk Python To Me Podcast
October 24, 2024 - 18:22 A YAML file, a pre-commit config YAML file, which then has a bunch of listings of here's a Git repository. 18:30 And if you install it as a Python package, here's a bunch of things that you can run on it, like check toml, check YAML and so on, right?
Top answer
1 of 1
12

pre-commit installs isolated environments for each of the tools such that they don't interfere with local development. It sounds like you're missing dependencies in that environment

Running pip install inside the cache environments is very not supported and you are likely to break pre-commit by doing that. They are intentionally private implementation detail so you don't mess with them!

You have two main options:

making your scripts work in isolation (the supported way)

set up your tools such that they specify their dependencies properly (you haven't shown your configuration, but my guess is you're calling some script?)

for repositories that get installed, the dependencies of your tool should be listed in your setup metadata (usually setup.py / setup.cfg / pyproject.toml)

For example, pre-commit/pre-commit-hooks specifies these dependencies:

# setup.cfg
install_requires =
    ruamel.yaml>=0.15
    toml

for local repositories with language: python, you should specify your dependencies in additional_dependencies -- for example:

-   repo: local
    hooks:
    -   id: run-the-thing
        name: run the thing
        entry: ./scripts/lint
        additional_dependencies: [six, ...]
        language: python
        types: [python]

repository local hooks (the escape hatch)

with language: system / language: script, pre-commit does not provision an environment. it is the responsibility of each user to set up such an environment. these are the escape hatch from the normal way because they kind of defeat the purpose of the framework in the first place (which is to provision the tools necessary on its own -- without every developer needing to carefully manage a bunch of tools)

For repo: local you'd use language: system and just hope your script produces a useful error message if the user's environment is misconfigured

-   repo: local
    hooks:
    -   id: run-the-thing
        name: run the thing
        entry: ./scripts/lint
        language: system
        types: [python]

disclaimer: I created pre-commit

🌐
PyPI
pypi.org › project › pre-commit-hooks
pre-commit-hooks · PyPI
Prevent giant files from being committed. Specify what is "too large" with args: ['--maxkb=123'] (default=500kB). Limits checked files to those indicated as staged for addition by git. If git-lfs is installed, lfs files will be skipped (requires git-lfs>=2.2.1) --enforce-all - Check all listed files not just those staged for addition. Simply check whether files parse as valid python...
      » pip install pre-commit-hooks
    
Published   Aug 09, 2025
Version   6.0.0
🌐
GitHub
github.com › pre-commit
pre-commit · GitHub
pre-commit/mirrors-clang-format’s past year of commit activity · Python 74 MIT 38 0 0 Updated · May 7, 2026 · mirrors-eslint Public · Mirror of eslint node package for pre-commit. There was an error while loading. Please reload this page. pre-commit/mirrors-eslint’s past year of commit activity ·
🌐
Medium
medium.com › @fistralpro › git-hooks-with-python-pre-commit-including-pylint-in-1-minute-5ef9781eb37c
Git-hooks with Python Pre-commit including Pylint in <1 minute | by Michael Murray | Medium
January 8, 2024 - Our simple flask hello world be ... to Part 2 for the pre-commit bit. mkdir hello_world cd hello_world python -m venv venv source ./venv/bin/activate pip install flask · We do not need flask, but I thought it useful to show that our venv packages will be ignored for the ...