AI Hints
CI/CD with GitHub Actions · Lesson 24 of 138

setup-python

The right version.

⏱ 2 min read▶ Video at 27:02🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Your code was written for a particular Python version. The runner has some Python installed, but maybe not the one you need. Setup python installs exactly the version you ask for, and puts it first on the path.

setup-python
From the video: setup-python
  • Your code needs a version
  • The runner may differ
  • setup-python picks it

Setting up Python

Python version takes a version in quotes. Remember, three point ten without quotes would become three point one. Cache, set to pip, saves downloaded packages between runs, so installs get faster. Then a normal run step can check the version, and install the requirements.

setup.ymlyaml
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-python@v5
    with:
      python-version: "3.12"
      cache: pip
  - run: python --version
  - run: pip install -r requirements.txt

A setup action for every language

Every popular language has a setup action. Setup node for JavaScript, setup java, setup go, and more. They all work the same way. A version input, and often a cache input. Learn one, and you know them all.

Pythonactions/setup-python
Node.jsactions/setup-node
Javaactions/setup-java
Goactions/setup-go

Summary

Setup python installs the exact version you need, and can cache packages. Next, running our tests in CI.

Key takeaways
  • python-version: "3.12"
  • cache: pip
  • One per language
Next up: Running Tests in CI — the heart of CI