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-pythonwith the targetpython-version. - Set
cache: pipto cache wheels keyed on your requirements file. - Use
python -m pipso 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 pytestGotchas
- On Windows the executable is
python;python3may not exist, so preferpython -m. - pip caching keys on the requirements/lock file, so a hit needs the file unchanged.
Related guides
How to Set Up a Specific .NET Version on Windows in GitHub ActionsPin one or more .NET SDK versions on a windows-latest runner in GitHub Actions with actions/setup-dotnet, inc…
How to Run Tests on a Windows and Linux Matrix in GitHub ActionsRun the same test job on Windows and Linux in GitHub Actions with an os matrix driving runs-on, and a portabl…