actions/setup-python@v7
Set up a specific version of Python and add the command-line tools to the PATH.
At a glance
- Latest major
v7- Repository
- actions/setup-python
- Inputs
- 13 (0 required)
- Outputs
- 3
- Runs using
node24- License
- MIT
- Last checked
Inputs and outputs come straight from the action's official action.yml. See our editorial standards.
Usage
- uses: actions/setup-python@v7Inputs
| Name | Required | Default | Description |
|---|---|---|---|
python-version | No | none | Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset. |
python-version-file | No | none | File containing the Python version to use. Example: .python-version |
cache | No | none | Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry. |
architecture | No | none | The target architecture (x86, x64, arm64) of the Python or PyPy interpreter. |
check-latest | No | false | Set this option if you want the action to check for the latest available version that satisfies the version spec. |
token | No | ${{ github.server_url == 'https://github.com' && github.token || '' }} | The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. This token is only sent to GitHub-owned hosts, never to a custom 'mirror'. |
mirror | No | https://raw.githubusercontent.com/actions/python-versions/main | Base URL for downloading Python distributions (only applies to CPython; PyPy and GraalPy are unaffected). Defaults to https://raw.githubusercontent.com/actions/python-versions/main. See docs/advanced-usage.md for details. |
mirror-token | No | none | Token used to authenticate requests to the host named in 'mirror'. Sent verbatim as the Authorization header, so include a scheme if your mirror needs one (e.g. 'Bearer <token>'). |
cache-dependency-path | No | none | Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies. |
update-environment | No | true | Set this option if you want the action to update environment variables. |
allow-prereleases | No | false | When 'true', a version range passed to 'python-version' input will match prerelease versions if no GA versions are found. Only 'x.y' version range is supported for CPython. |
freethreaded | No | false | When 'true', use the freethreaded version of Python. |
pip-version | No | none | Used to specify the version of pip to install with the Python. Supported format: major[.minor][.patch]. |
Outputs
| Name | Description |
|---|---|
python-version | The installed Python or PyPy version. Useful when given a version range as input. |
cache-hit | A boolean value to indicate a cache entry was found |
python-path | The absolute path to the Python or PyPy executable. |
Read an output with ${{ steps.<step-id>.outputs.<name> }}; the step needs an id.
Examples
Python with the pip cache
Install a Python minor version and cache pip downloads between runs.
name: Example
on:
push:
branches: [main]
permissions:
contents: read
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: 3.12
cache: pip
- run: pip install -r requirements.txt
- run: pytestSeveral Python versions
Combine with a matrix to test a library on every supported Python.
name: Example
on:
push:
branches: [main]
permissions:
contents: read
jobs:
example:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- run: python --versionEach example passed actionlint (syntax, expressions and the inputs it knows for this action). They were not run in a live repository, so replace placeholder values such as names, ARNs and paths with your own.
Something out of date or wrong? Report it on our Contact page. This page is rebuilt from the action's repository roughly once a week.