pre-commit hooks fail 'No module named pre_commit' after repo move due to hardcoded Python path
pre-commit git hooks fail with 'No module named pre_commit' after moving repo to a different machine. The generated hooks (.git/hooks/pre-commit, .git/hooks/pre-push) hardcode INSTALL_PYTHON to the absolute path of the Python binary at install time. When the repo moves to a different machine, the hook runs the wrong interpreter which lacks the pre-commit module. The fallback (command -v pre-commit) never fires because the stale path is still a valid executable (system Python).
Reinstall the hooks on the current machine to regenerate them with the correct INSTALL_PYTHON path:
pre-commit install pre-commit install --hook-type pre-push
This overwrites the hook scripts with the correct absolute path to the Python that has pre-commit installed. The error message does not hint at the cause; inspect .git/hooks/pre-push and look for the INSTALL_PYTHON variable to confirm it points to a stale path.