Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Running a Specific Python Version

00:00 To make use of the setup Python action, go into your hello_python.yaml file and add a new section. I name it run_specific_python with underscores and colon in the end. As a name, Run Python 3.13,

00:17 and just like the job above, it runs on ubuntu-latest.

00:23 Then add the steps property and underneath, you use a new property starting with a dash uses:. So with the uses property, you can refer to actions that GitHub knows about.

00:38 For example, actions/setup-python, and then you can define the version you want to use with @v5. With @ and v, and then a number behind it, GitHub Actions are versioned.

00:53 In my experience, GitHub Actions versions don’t change so much, so chances are that the versions we’re using in this video course are still the same. But if you want to be really sure, you can head to the GitHub Actions page of setup-python and later of checkout, and see which exact versions are the newest versions there.

01:14 In this video course, it’s setup-python@v5 to use version five.

01:21 And then in the next line, basically indented at the same level as uses, then you use the with property. The word with must be exactly underneath the word uses here.

01:34 Visually, it doesn’t align exactly on my screen because I’m not using a monospace font here. If you’re curious about why, ask me in the comments, I’m happy to elaborate on this.

01:44 However, with a monospace font, both would align perfectly right now. Visually, it’s not for me, but for you it should. And then indented once more you can use the python-version property with the value in quotes, '3.13'.

02:02 So here you are telling the setup Python action that you want to use the Python version '3.13'. Here I’m using single quotes. Again, YAML doesn’t care so much.

02:14 If you want to be thorough, you can use what kind of quotes, but I want to show that you can use any type of quotes here in the YAML file.

02:22 And that means for GitHub that for any upcoming steps of this job, the runner should use Python 3.13. And then just like before, use the run property to display the current Python version.

02:47 Let’s commit and push the changes,

02:54 and then see if both jobs run correctly.

03:00 And there you go. Both jobs ran successfully. The run Ubuntu’s Python version ran just like before, and there you can see the run Python 3.13 job. If you have a look at this job, you can see the output Python 3.13 in the log file, so that means this step is specifically running Python 3.13.

03:23 Perfect. Now that you are very specific about the Python version that your workflow is using, it’s time to actually add some Python code to your project.

Become a Member to join the conversation.