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@v5with apython-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.pyGotchas
- The default runner Python may differ from your target; pin
python-versionexplicitly. - Use
cache: pipon setup-python to avoid reinstalling dependencies every run.
Related guides
How to Run a Node.js Script in GitHub ActionsRun a Node.js script in GitHub Actions with actions/setup-node, installing dependencies with npm ci, then inv…
How to Run a Script With a Specific Interpreter in GitHub ActionsRun a GitHub Actions script under a specific interpreter with the step shell key, choosing bash, sh, pwsh, py…