{"id":449,"library":"pre-commit","title":"pre-commit","description":"A framework for managing and maintaining multi-language pre-commit hooks. Current version: 4.5.1. Released on December 16, 2025. Maintained with regular updates.","status":"active","version":"4.5.1","language":"python","source_language":"en","source_url":"https://github.com/pre-commit/pre-commit","tags":["pre-commit","git hooks","python","multi-language","code quality"],"install":[{"cmd":"pip install pre-commit","lang":"bash","label":"Install pre-commit"}],"dependencies":[{"reason":"Required for creating isolated environments for hooks.","package":"virtualenv"}],"imports":[{"note":"Ensure correct import path to avoid ImportError.","symbol":"pre_commit","correct":"import pre_commit"}],"quickstart":{"code":"import os\n\n# Install pre-commit\nos.system('pip install pre-commit')\n\n# Create a configuration file\nwith open('.pre-commit-config.yaml', 'w') as f:\n    f.write('repos:\\n  - repo: https://github.com/pre-commit/mirrors-black\\n    rev: v22.10.0\\n    hooks:\\n      - id: black\\n')\n\n# Install the git hook scripts\nos.system('pre-commit install')\n\n# Run hooks against all files\nos.system('pre-commit run --all-files')","lang":"python","description":"A script to install pre-commit, set up a configuration file with the Black formatter, install git hooks, and run them against all files."},"warnings":[{"fix":"Use non-editable installations or adjust tooling to handle new attributes.","message":"Editable installs may break due to changes in `__editable__` and `__path_hook__` attributes.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Install `virtualenv` using `pip install virtualenv`.","message":"Ensure that the `virtualenv` package is installed to create isolated environments for hooks.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure Git is installed and configured on the system where pre-commit is run, and execute pre-commit commands from within a directory that is part of a Git repository.","message":"Pre-commit hooks require Git to be installed on the system and the command must be run within a valid Git repository.","severity":"breaking","affected_versions":"All"},{"fix":"Ensure that Git is installed in the environment and that the 'pre-commit' command is executed inside a Git repository.","message":"pre-commit hooks require Git to be installed and the command to be run within a Git repository. Failure to meet these conditions results in a 'git failed' error.","severity":"breaking","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-05-12T13:53:21.564Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Activate your virtual environment (if using one) or ensure `pre-commit` is installed and its executable is discoverable. For Python virtual environments, use `source venv/bin/activate` (Linux/macOS) or `.\\venv\\Scripts\\activate` (Windows) before running `pre-commit`. If not installed, run `pip install pre-commit`.","cause":"The `pre-commit` executable is not found in your system's PATH, often because it was installed in a virtual environment that is not currently active, or it was never installed globally or in the active environment.","error":"pre-commit: command not found"},{"fix":"Carefully check your `.pre-commit-config.yaml` for YAML syntax errors, especially indentation. Ensure the file is named `.pre-commit-config.yaml` and is located at the root of your repository. Use a YAML linter or validator to identify specific issues. Example of a common error: `mapping values are not allowed in this context`.","cause":"The `.pre-commit-config.yaml` file contains syntax errors (e.g., incorrect indentation, invalid mapping values, or missing required keys) preventing `pre-commit` from parsing it correctly, or the file does not exist where expected.","error":"An unexpected error has occurred: InvalidConfigError: ==> File .pre-commit-config.yaml"},{"fix":"Run `pre-commit install` to reinstall the Git hook script. Ensure the script at `.git/hooks/pre-commit` has executable permissions (`chmod +x .git/hooks/pre-commit`). If the error persists and you previously used a different hook system (like Node.js `pre-commit`), manually remove the old hook file from `.git/hooks/pre-commit`.","cause":"The Git pre-commit hook script, which `pre-commit` installs, either does not exist at the expected path (`.git/hooks/pre-commit`), has incorrect file permissions, or is referencing a non-existent internal script (e.g., from a removed Node.js `pre-commit` package).","error":"fatal: cannot run .git/hooks/pre-commit: No such file or directory"},{"fix":"For Python hooks, ensure `default_language_version: python: python3` (or a specific version like `python3.X`) is set in your `.pre-commit-config.yaml`. For other languages, ensure the required tools are installed and accessible by `pre-commit`'s environment. For local hooks (`language: system`), verify the executable is in your system's PATH.","cause":"A hook defined in your `.pre-commit-config.yaml` requires an executable (like `python`, `node`, etc.) that `pre-commit` cannot find in the isolated environment it sets up for that hook, or on the system's PATH.","error":"CalledProcessError: command: ('python', '-mpip', 'install', '.') return code: 1 expected return code: 0 stdout: Executable 'python' not found"},{"fix":"Review the output in your terminal to see which specific hook failed and the reasons for its failure. Correct the issues reported by the hook (e.g., fix linting errors, format the code, resolve test failures) and then attempt to commit again. If you temporarily need to bypass the hooks, use `git commit --no-verify` (not recommended for general use).","cause":"One of your configured pre-commit hooks failed its checks (e.g., a linter found issues, a formatter detected unformatted code, or tests failed), causing it to exit with a non-zero status code.","error":"pre-commit: We've failed to pass the specified git pre-commit hooks as the <hook_id> hook returned an exit code (1)."}],"ecosystem":"pypi","meta_description":null,"install_score":80,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"31.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"32M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"33.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"35M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"25.4M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"27M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"25.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"26M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"30.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"32M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}