Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 5

Why use setup-python action instead of a python container?

Solved! Go to Solution.

Can you explain the pros and cons of both solutions?

 

steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
  with:
    python-version: '3.7' 
- run: python my_script.py

vs

container: python:3.7
runs-on: ubuntu-latest
steps:
    - uses: actions/checkout@v1
    - run: python my_script.py
4 Replies
Highlighted
GitHub Partner
Message 2 of 5

Re: Why use setup-python action instead of a python container?

I have a few summary here for your reference:

  • If using setup-python action in a job which does not set a container, the setup-python step will run in its container, other steps that don't already specify a container will directly run on the host specified by runs-on. And other container actions will run in themselves container.
  • If set a container on the job, any steps in this job that don't already specify a container will run in this container. Other container actions in this job will run as sibling containers on the same network with the same volume mounts.
  • The setup-python action only uses versions of Python already installed in the cache, and the action will fail if no matching versions are found. More details about the available versions of Python that are installed see here. Current available versions of Python are listed below. If set a python container on the job, you have more versions of Python to select.
Highlighted
Copilot Lvl 3
Message 3 of 5

Re: Why use setup-python action instead of a python container?

Thank you for your detailed answer. But I think you miss the main point of my question. I will rephrase.

 

My job needs Python 3.7 to run. Today I have two solutions: actions/setup-python or container: python:3.7.

In both cases, my job will pass.

 

What's the pro and cons of these two solutions?

Highlighted
Solution
GitHub Staff
Message 4 of 5

Re: Why use setup-python action instead of a python container?

@tetienne Containers are only an option on Linux.  If you need to test your python application on Windows or MacOS then using setup-python is the right option.  It can also be a lot faster as in many cases you can use a python that is already downloaded on the runner rather than having to wait for a container to download.

Highlighted
Copilot Lvl 3
Message 5 of 5

Re: Why use setup-python action instead of a python container?

Oh I was not aware of container restricted only to Linux host.

 

I will try to perform some tests to see the speed difference between both. But indeed it makes sense.

 

Thx for your answer.