Skip to content
Latchkey

How to Set Up Python on Windows in GitHub Actions

actions/setup-python installs the requested Python on Windows and can cache pip downloads by lockfile.

Add actions/setup-python with a python-version and cache: pip. On Windows the interpreter is python (not python3), so write portable commands accordingly.

Steps

  • Add actions/setup-python with the target python-version.
  • Set cache: pip to cache wheels keyed on your requirements file.
  • Use python -m pip so the call works the same on Windows and Linux.

Workflow

.github/workflows/ci.yml
jobs:
  test:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
          cache: pip
      - run: python -m pip install -r requirements.txt
      - run: python -m pytest

Gotchas

  • On Windows the executable is python; python3 may not exist, so prefer python -m.
  • pip caching keys on the requirements/lock file, so a hit needs the file unchanged.

Related guides

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