Skip to content
Latchkey

actions/setup-python: Install Python in CI

setup-python installs the Python version you ask for and can cache pip downloads.

Pin a Python version (or matrix several) and optionally cache pip, pipenv, or poetry to speed up installs.

Key inputs (with:)

  • python-version: e.g. 3.12 or a range like 3.x.
  • python-version-file: read from .python-version or pyproject.toml.
  • cache: pip, pipenv, or poetry.
  • cache-dependency-path: requirements or lock file path.
  • architecture: x64 or arm64.

Example workflow

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.10', '3.11', '3.12']
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: pip
      - run: pip install -r requirements.txt
      - run: pytest

On any runner

setup-python works on any runner. Latchkey managed runners run it unchanged, cheaper and self-healing.

Key takeaways

  • Use a matrix to test multiple Python versions in parallel.
  • cache: pip skips re-downloading wheels between runs.
  • python-version-file keeps CI in sync with local tooling.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →