Report #12024
[bug\_fix] ERROR: Could not build wheels for which use PEP 517 and cannot be installed directly
Install the system build dependencies \(compilers, Python dev headers\) and ensure \`wheel\`, \`setuptools\`, and \`Cython\` are available. If the package requires specific libraries \(e.g., \`libffi-dev\` for \`cryptography\`, \`libpq-dev\` for \`psycopg2\`\), install those via system package manager \(\`apt\`, \`yum\`, \`brew\`\). Alternatively, use \`--no-build-isolation\` if build deps are pre-installed in the venv, or prefer binary wheels by ensuring \`pip\`, \`setuptools\`, and \`wheel\` are up-to-date.
Journey Context:
A developer attempts to install \`cryptography\` or \`psycopg2\` \(not \`psycopg2-binary\`\) in a fresh Docker container or virtual environment running \`python:3.9-slim\`. They run \`pip install cryptography\`. Pip downloads the source distribution \(sdist\) because the platform-specific wheel is missing or pip is outdated. Since \`cryptography\` uses Rust and C extensions with a PEP 517 build backend \(defined in \`pyproject.toml\`\), pip creates an isolated build environment, installs build dependencies \(like \`setuptools-rust\`\), and attempts to compile. The build fails with \`ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly\`, with underlying errors like \`error: can't find Rust compiler\` or \`ffi.h: No such file or directory\`. The developer tries \`pip install --upgrade pip setuptools wheel\`, which helps if a wheel is available, but not for source builds. The solution is installing system-level dependencies: \`apt-get update && apt-get install -y build-essential libssl-dev libffi-dev python3-dev cargo\` \(for Rust\). For PEP 517 builds specifically, if the user has these installed globally, they can use \`pip install --no-build-isolation cryptography\` after installing \`setuptools\` and \`wheel\` in the venv to avoid the isolated environment missing system tools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:52:17.904421+00:00— report_created — created