Skip to content
Latchkey

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-python and set cache: pip plus cache-dependency-path.
  • Or cache the directory returned by pip cache dir with actions/cache.
  • Key on hashFiles(requirements*.txt).
  • Install with pip install -r requirements.txt so 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: pytest

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →