# python

> For the complete documentation index, see [llms.txt](https://docs.ringleader.dev/llms.txt).


> The distribution's own Python 3, together with pip and the venv module.


Installs the distribution's **Python 3**, with **pip** and **venv**.

```yaml
devtools:
  - name: python
```

You get whichever Python 3 the workstation's distribution ships, ready to make virtual
environments. Use one for your project; recent Debian and Ubuntu releases refuse
`pip install` into the system interpreter, and a virtual environment is where installs
go:

```bash
python3 -m venv ~/.venvs/app
. ~/.venvs/app/bin/activate
pip install -r requirements.txt
```

This devtool means "this workstation runs Python", not "this workstation runs Python
3.12". If you need a specific interpreter, see [Version behavior](#version-behavior).

## Version behavior

| `version` | Result |
|-----------|--------|
| omitted | the distribution's `python3`, with pip and venv |
| anything else | refused, with a message explaining the alternatives |

Pinning a version is refused because Python publishes no official Linux binary release
and no per-minor package repository, so there is nothing to install a pinned minor from
that works the same on every distribution Ringleader supports. If you need a specific interpreter, either declare it in `packages` with a
`packageRepositories` entry for a repository that publishes it, or pick a base `image`
that already carries it.

## Updates

Python comes from the distribution's packages, so it moves with the
[operating system updates](https://docs.ringleader.dev/reference/tools/devtools/#operating-system-updates) the workstation applies.
`updatePolicy: latest` does not change which of those updates it takes.

## Python command-line tools

To install a Python command-line tool such as `ruff`, declare it as a `pypi`
[package](https://docs.ringleader.dev/workstations/packages-tools-settings/package-installation/#add-a-package) instead
of running `pip` yourself. Ringleader installs it with [`uv`](https://docs.ringleader.dev/reference/tools/devtools/uv/),
on a Python of its own, so it does not depend on this devtool.

## Installed packages

| Distribution | Packages |
|---|---|
| Debian / Ubuntu | `python3`, `python3-pip`, `python3-venv` |
| Alpine | `python3`, `py3-pip` |

## Example

Install Python and create the project's virtual environment as the login user:
```yaml
apiVersion: workstations.ringleader.dev/v1
kind: WorkstationConfig
metadata:
  name: python-box
  namespace: dev
spec:
  selector:
    matchLabels:
      tier: dev
  devtools:
    - name: python
  scripts:
    - name: project-venv
      phase: user
      content: |
        set -e
        python3 -m venv "$HOME/.venvs/app"
        "$HOME/.venvs/app/bin/pip" install -r "$HOME/src/app/requirements.txt"
```

## Notes

- The workstation counts as having this devtool once `python3 -m pip` runs, so a
  workstation that lost pip or venv is repaired on the next setup run.
- Works on Debian, Ubuntu and Alpine.

