Python in GitHub actions
Pip packages¶
The actions/setup-python actions installs python
with a specific version and could cache downloaded Python packages. (But not the installed environment).
uv is a drop-in replacement for pip
, an extremely fast Python package and project manager written in Rust. uv
caches the environment by default.
name: UV example
env:
UV_SYSTEM_PYTHON: 1
jobs:
python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
check-latest: true
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
version: "latest"
- name: Install requirements
run: uv pip install -r requirements.txt
Conda packages¶
The mamba-org/setup-micromamba action installs the micromamba package manager and conda package dependencies. It also caches the Python runtime environment.
- uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
init-shell: bash
cache-environment: true
post-cleanup: 'all'
- name: Run custom command in micromamba environment
shell: micromamba-shell {0}
run: python --version