How to Cache pip Wheels in GitHub Actions
pip rebuilds and re-downloads wheels on each fresh runner unless its cache directory is preserved.
Use actions/setup-python with cache: pip, or cache the pip cache dir directly keyed on your requirements files.
Steps
- Add
actions/setup-pythonand setcache: pippluscache-dependency-path. - Or cache the directory returned by
pip cache dirwithactions/cache. - Key on
hashFiles(requirements*.txt). - Install with
pip install -r requirements.txtso wheels populate the cache.
Workflow
.github/workflows/python.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: requirements.txt
- run: pip install -r requirements.txt
- run: pytestGotchas
- The pip cache holds wheels, not an installed venv; install still runs, just without network fetches.
- For Poetry or uv, cache their own caches instead of the pip cache.
- Latchkey keeps the wheel cache warm so Python installs are faster and recover from registry blips.
Related guides
How to Cache Playwright Browsers in GitHub ActionsCache the Playwright browser binaries in GitHub Actions, keyed on the installed Playwright version, so e2e ru…
How to Cache Maven .m2 in GitHub ActionsCache the Maven local repository (~/.m2/repository) in GitHub Actions, keyed on pom.xml, so Java builds skip…