Skip to content
Latchkey

How to Run a Python Script in GitHub Actions

Set up the interpreter with actions/setup-python, install what you need, then run the script with python.

Use actions/setup-python to pin a version, install dependencies with pip, then call python script.py. Pinning the version keeps behavior reproducible.

Steps

  • Add actions/setup-python@v5 with a python-version.
  • Install requirements with pip install -r requirements.txt.
  • Run the script with python scripts/report.py.

Workflow

.github/workflows/ci.yml
jobs:
  report:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - run: pip install -r requirements.txt
      - run: python scripts/report.py

Gotchas

  • The default runner Python may differ from your target; pin python-version explicitly.
  • Use cache: pip on setup-python to avoid reinstalling dependencies every run.

Related guides

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