Skip to content
Latchkey

pip "Could not build wheels ... which use PEP 517" in CI

pip used the package’s PEP 517 build backend to make a wheel and the backend failed. The summary line is generic; the real failure - a missing compiler, header, or build dependency - is in the backend output above it.

What this error means

After a build log, pip prints ERROR: Could not build wheels for <pkg>, which is required to install pyproject.toml-based projects (sometimes "which use PEP 517"). Nothing installs because the wheel build never completed.

pip output
Building wheels for collected packages: lxml
  Building wheel for lxml (pyproject.toml) ... error
  ...
  src/lxml/etree.c:96:10: fatal error: libxml/xmlversion.h: No such file or directory
ERROR: Could not build wheels for lxml, which is required to install
pyproject.toml-based projects

Common causes

A native build dependency is missing

The PEP 517 backend needs a compiler, system headers, or a library (here libxml2 dev files) that the runner does not have, so the build aborts.

No wheel for this platform/Python

With no compatible prebuilt wheel, pip must build from source - and any gap in the toolchain fails the PEP 517 build.

How to fix it

Read the backend error and install what it needs

  1. Scroll up to the first fatal error:/error: line in the build output.
  2. Install the missing system dev package (e.g. libxml2-dev libxslt1-dev for lxml).
  3. Re-run; the PEP 517 build should now complete.

Prefer a prebuilt wheel

Force a binary wheel to skip the source build when one exists for your platform.

Terminal
python -m pip install --upgrade pip
pip install --only-binary :all: lxml

Install the toolchain for source builds

Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y build-essential python3-dev libxml2-dev libxslt1-dev

How to prevent it

  • Bake required dev libraries into images that build from source.
  • Prefer wheels (--only-binary) and a current pip in CI.
  • Pin Python to a version with wheel coverage for native deps.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →