Setting Up Pre-Push Git Hooks and Python Tools on Linux¶
This project uses a pre-push Git hook to automatically update requirements.txt
from your Python scripts.
To use this workflow, you need to have the pipreqs
tool installed and available to Git.
Recommended: Install pipreqs with pipx¶
Install pipx (if not already installed):
sudo pacman -S python-pipx
Install pipreqs using pipx:
pipx install pipreqs
Verify pipreqs works:
pipreqs --version
Alternative: Use a Python Virtual Environment¶
If you prefer or are using a virtualenv for your project:
Create and activate a virtualenv:
python -m venv .venv source .venv/bin/activate
Install pipreqs inside the virtualenv:
pip install pipreqs
Edit the git hook to call pipreqs using the full path:
.venv/bin/pipreqs "$TMPDIR" --force
Why not use plain pip install?¶
Modern Linux distros restrict system-wide pip installs to prevent breaking OS packages.
Do NOT use sudo pip install pipreqs
or pip install pipreqs
globally.
Troubleshooting¶
If you see
pipreqs: command not found
, make sure you installed it with pipx and that~/.local/bin
is in your$PATH
.You can check your path with:
echo $PATH
Need help?¶
Open an issue or ask in the project discussion!