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
🌐
PyPI
pypi.org › project › pre-commit
pre-commit · PyPI
pip install pre-commit Copy PIP instructions · Latest version · Released: Apr 21, 2026 · A framework for managing and maintaining multi-language pre-commit hooks. These details have been verified by PyPI · asottile · These details have ...
      » pip install pre-commit
    
Published   Apr 21, 2026
Version   4.6.0
🌐
pre-commit
pre-commit.com
pre-commit
jobs: - job: precommit # ... variables: PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache steps: # ...
🌐
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.2K users
Forked by 961 users
Languages   Python 97.4% | R 2.0% | Shell 0.5% | Dockerfile 0.1% | Lua 0.0% | Ruby 0.0%
🌐
Reddit
reddit.com › r/python › users of pre-commit, do you install it globally or per project?
r/Python on Reddit: Users of pre-commit, do you install it globally or per project?
February 22, 2023 -

I know that Python dependency and environment management is a messy topic, so not trying to start any flame wars or anything, just looking for practical advice.

My usual tooling is

  • asdf to install different versions of Python

  • poetry for project management

  • pipx for CLI tools written in Python that are useful in general and aren’t a dependency on a project

This article seems to have very solid advice overall, but I am unsure if installing pre-commit per project is the best way.

In other words, is poetry or pipx ideal for pre-commit?

I realize that everyone will have different needs and preferences, so curious what the community thinks.

Edit: to the downvoters, can you kindly drop a comment why you think this is a stupid question?

🌐
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 - pip install black pip install flake8 pip install isort · Start by creating a basic Pre-commit configuration file at the base of your working directory:
🌐
DEV Community
dev.to › vaiolabs_io › amazing-pre-commit-and-how-to-use-it-5enb
Amazing `pre-commit` and How To Use It - DEV Community
February 27, 2025 - This tutorial will guide you through installing, configuring, and using pre-commit in your projects.
Find elsewhere
🌐
Architecture-performance
architecture-performance.fr › accueil › dev › some pre-commit git hooks for python
Some Pre-commit git hooks for Python - Architecture et Performance
April 1, 2022 - First we need to install pre-commit, which is a framework for managing and maintaining multi-language pre-commit hooks: $ pip install pre-commit $ pre-commit --version pre-commit 2.11.1
🌐
PyPI
pypi.org › project › pre-commit-hooks
pre-commit-hooks · PyPI
As a result, it will ignore any setting of files, exclude, types or exclude_types. Set always_run: false to allow this hook to be skipped according to these file filters. Caveat: In this configuration, empty commits (git commit --allow-empty) would always be allowed by this hook. Checks that all your JSON files are pretty.
      » pip install pre-commit-hooks
    
Published   Aug 09, 2025
Version   6.0.0
🌐
Medium
medium.com › @liwp.stephen › install-pre-commit-on-mac-with-pip3-e18b5d12d43f
Install pre-commit on mac with pip3 | by Stephen Lee | Medium
September 19, 2022 - Install pre-commit on mac with pip3 We use the pre-commit to check code before commit on git, before we setup the environment, we need to install the pre-commit first, but in one of my friend’s …
🌐
Apache
hamilton.apache.org › how-tos › pre-commit-hooks
pre-commit hooks - Hamilton
The preferred way of working with pre-commit hooks is through the prek library. This library allows you to import and configure hooks for your repository with a .pre-commit-config.yaml file. install the prek library · pip install prek · add a .pre-commit-config.yaml to your repository ·
🌐
F-Lab & Company
f-lab.ai › en › insight › how-to-use-pre-commit-20260113
프리커밋(Pre-commit)으로 코드 품질 관리하기
January 13, 2026 - pip install pre-commit · 설치 후, 프로젝트 루트 디렉토리에 `.pre-commit-config.yaml` 파일을 생성하고, 원하는 훅을 설정합니다.
🌐
Damavis
blog.damavis.com › inicio › software › automate code quality checks with pre-commit in python
Improve your Python code automatically with Pre-commit Hooks
September 16, 2025 - These are general checks, but we can add new hooks according to our preferences. In Supported Hooks you can find a list with different hooks available. In our case, we are going to customize the configuration file as follows: default_stages: - commit - push fail_fast: true repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.2.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - id: detect-private-key - id: double-quote-string-fixer - repo: https://github.com/asottile/dead rev: v1.5.0 hooks: - id: dead - repo: https://github.com/dannysepler/rm_unneeded_f_str rev: v0.1.0 hooks: - id: rm-unneeded-f-str
🌐
Better Programming
betterprogramming.pub › 2-use-cases-of-python-pre-commit-hooks-to-tidy-up-your-git-repositories-8d86c9c4f06b
2 Use Cases of Python Pre-commit Hooks to Tidy Up Your Git Repositories | by Eldad Uzman | Better Programming
April 13, 2022 - Install pre-commit from pip: pip install pre-commit · 2. Create the pre-commit configuration file in your repository (about that, shortly) 3. Install the commit configuration into your git repo: pre-commit install · And from that moment on, ...
🌐
PyPI
pypi.org › project › pre-commit-uv
pre-commit-uv · PyPI
Use uv to create virtual environments and install packages for pre-commit. With pipx: pipx install pre-commit pipx inject pre-commit pre-commit-uv · With uv: uv tool install pre-commit --with pre-commit-uv --force-reinstall · Compared to upstream pre-commit will speed up the initial seed operation.
      » pip install pre-commit-uv
    
Published   Feb 18, 2026
Version   4.2.1