Fix pip subprocess-exited-with-error: Failed building wheel
pip subprocess-exited-with-error and Failed building wheel mean the build failed, usually a source build with no wheel. Read the line above [end of output].
error: subprocess-exited-with-error × Building wheel for netifaces (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [28 lines of output] … error: [Errno 2] No such file or directory: 'gcc' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for netifacesThis header means a subprocess pip started — the package build — failed. As the note: line says, it is not pip's own failure: the cause is in **the last few lines above [end of output]**. The most common case is the one above: no wheel (a prebuilt .whl) for your Python and OS, so pip built the source distribution (.tar.gz) and a tool was missing; install the tool that line names, or pick a wheel you do not have to build. The same header also appears when you chose a source build on purpose (--no-binary, a local source tree) or when installing build dependencies or the build backend itself fails, so first find the stage that stopped.
[1] Look at the file name on the Downloading … line first. A .tar.gz means pip got source and will build. Then read the × line to see which stage stopped.
× line | Where it stopped | Cause line seen in testing |
|---|---|---|
Getting requirements to build wheel did not run successfully | Build preparation (metadata) | Error: pg_config executable not found. (psycopg2 2.9.10) |
Building wheel for … did not run successfully | Compiling | No such file or directory: 'gcc' (netifaces 0.11.0) |
Warnings near the top of [34 lines of output], such as SetuptoolsDeprecationWarning: License classifiers are deprecated., showed up in both cases and are not the cause. Read only the Error:/error: lines at the bottom.
[2] Check whether that release has a wheel for your environment. With --only-binary=:all: pip will not use source, so if no wheel exists it stops right away instead of building:
$ python -m pip install --no-cache-dir --only-binary=:all: netifaces==0.11.0ERROR: Could not find a version that satisfies the requirement netifaces==0.11.0 (from versions: none)ERROR: No matching distribution found for netifaces==0.11.0If you get this, building is the only route on this Python version. To move to a release that has a wheel (a newer package release, or a Python version it ships wheels for), check cp312 and manylinux…_x86_64 in the file names under "Download files" on PyPI. Choosing one works the same as steps [3] and [4] of pip No matching distribution found.
[3] If a wheel-only package does the same job, use it. psycopg2 publishes psycopg2-binary, which needs no build:
$ python -m pip install --no-cache-dir psycopg2-binary==2.9.10 | tail -1$ python -c 'import psycopg2; print(psycopg2.__version__)'Successfully installed psycopg2-binary-2.9.102.9.10 (dt dec pq3 ext lo64)The import name is still psycopg2. The psycopg docs, though, pitch psycopg2-binary at beginners, advise the source distribution for production, and say not to use it as a dependency of packages you publish. On a production server, go to [4].
[4] Install the build tools, one at a time, watching whether the cause line changes. Some packages need only a compiler; others need library headers too. These results are from Debian (including the official python:*-slim images):
# apt-get update -qq && apt-get install -y -qq gcc > /dev/null 2>&1; gcc --version | head -1$ python -m pip install --no-cache-dir netifaces==0.11.0 | tail -2$ python -m pip install --no-cache-dir psycopg2==2.9.10 2>&1 | grep -E 'Error:|Successfully'gcc (Debian 14.2.0-19) 14.2.0Installing collected packages: netifacesSuccessfully installed netifaces-0.11.0 Error: pg_config executable not found.netifaces built with gcc alone; psycopg2 still wanted pg_config. As the psycopg docs say, the libpq header package brings pg_config with it:
# apt-get install -y -qq libpq-dev > /dev/null 2>&1; which pg_config$ python -m pip install --no-cache-dir psycopg2==2.9.10 | tail -2/usr/bin/pg_configInstalling collected packages: psycopg2Successfully installed psycopg2-2.9.10Python.h: No such file or directory means the Python headers are missing. With a distro Python, install python3-dev (the official python images already include them, so it did not come up here). In Docker, keep build tools in a build stage and copy only the installed result into the runtime image.
[5] If pip ends with ERROR: Exception: and a long traceback instead of subprocess-exited-with-error, it is a different case. Installing the old numpy==1.24.4, which has no wheel for Python 3.12, ended during build preparation with:
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Cannot import 'setuptools.build_meta'That release has no Python 3.12 wheel, and even its source build preparation would not run here. A compiler will not fix it; raise the pin to a release with a wheel for your Python, as in [2].