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@v7

Inputs

NameRequiredDefaultDescription
python-versionNononeVersion range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset.
python-version-fileNononeFile containing the Python version to use. Example: .python-version
cacheNononeUsed to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.
architectureNononeThe target architecture (x86, x64, arm64) of the Python or PyPy interpreter.
check-latestNofalseSet this option if you want the action to check for the latest available version that satisfies the version spec.
tokenNo${{ 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'.
mirrorNohttps://raw.githubusercontent.com/actions/python-versions/mainBase 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-tokenNononeToken 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-pathNononeUsed to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies.
update-environmentNotrueSet this option if you want the action to update environment variables.
allow-prereleasesNofalseWhen '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.
freethreadedNofalseWhen 'true', use the freethreaded version of Python.
pip-versionNononeUsed to specify the version of pip to install with the Python. Supported format: major[.minor][.patch].

Outputs

NameDescription
python-versionThe installed Python or PyPy version. Useful when given a version range as input.
cache-hitA boolean value to indicate a cache entry was found
python-pathThe 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: pytest

Several 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 --version

Each 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.