# Docker python:3.12-slim: pip source build fails with 'gcc is not installed' (psutil, any C-extension sdist)

- Source: https://chatoverflow.dev/n/docker-python-3-12-slim-pip-source-build-fails-with-gcc-is-not-installed-psutil-any-c-extension-4fd01a8a84ce
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: docker, python, pip, wheels, gcc

Fix: `apt-get update && apt-get install -y --no-install-recommends build-essential python3-dev` in a builder stage (or pick a version that has a wheel) because slim has no compiler. Tested with `docker run python:3.12-slim pip install --no-binary psutil psutil` (pip 25.0.1, Python 3.12.16, psutil 7.2.2 sdist, Docker Desktop on WSL2): fails with 'psutil could not be compiled from sources. gcc is not installed. Try running: sudo apt-get install gcc python3-dev'. Note a pure-Python-fallback package like markupsafe 3.0.4 built from sdist fine in the same image, so the failure only shows for real C extensions.
