pip subprocess-exited-with-error 원인 읽기
pip subprocess-exited-with-error · Failed building wheel 은 빌드 실패입니다. 대개 맞는 휠이 없어 소스를 빌드하다 납니다. [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 netifacespip 이 띄운 하위 프로세스(패키지 빌드)가 실패했다는 표제입니다. pip 자신의 오류가 아니라는 note: 줄 그대로, 원인은 **[end of output] 바로 위 몇 줄**에 있습니다. 가장 흔한 것은 위 예처럼 지금 Python·OS 에 맞는 휠(미리 빌드된 .whl)이 없어 소스 배포(.tar.gz)를 직접 빌드하다 도구가 없어 멈춘 경우이고, 그때는 그 줄이 말하는 도구를 넣거나 빌드하지 않아도 되는 휠을 고르면 풀립니다. --no-binary 나 로컬 소스 설치로 일부러 빌드를 고른 경우, 빌드 의존성 설치나 빌드 백엔드 자체가 실패한 경우에도 같은 표제가 나오므로 어느 단계에서 멈췄는지부터 봅니다.
[1] 첫 줄 Downloading … 의 파일 이름부터 봅니다. .tar.gz 면 소스를 받은 것이고 빌드로 갑니다. 그다음 × 줄로 어느 단계에서 멈췄는지 봅니다.
× 줄 | 멈춘 곳 | 시험에서 본 원인 줄 |
|---|---|---|
Getting requirements to build wheel did not run successfully | 빌드 준비(메타데이터) | Error: pg_config executable not found.(psycopg2 2.9.10) |
Building wheel for … did not run successfully | 컴파일 | No such file or directory: 'gcc'(netifaces 0.11.0) |
[34 lines of output] 안 앞쪽의 SetuptoolsDeprecationWarning: License classifiers are deprecated. 같은 경고는 두 경우 모두 나왔지만 원인이 아닙니다. 맨 아래 Error:·error: 줄만 읽습니다.
[2] 그 판에 내 환경용 휠이 있는지 확인합니다. --only-binary=:all: 를 붙이면 pip 이 소스를 쓰지 않으므로, 휠이 없으면 빌드 대신 바로 이렇게 끝납니다.
$ 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.0이렇게 나오면 이 Python 판에는 빌드 말고 길이 없습니다. 휠이 있는 다른 판(패키지의 새 판, 또는 휠이 나온 Python 판)으로 옮길 수 있는지 PyPI 의 「Download files」 목록에서 파일 이름의 cp312·manylinux…_x86_64 를 봅니다. 고르는 법은 pip No matching distribution found의 [3]·[4] 와 같습니다.
[3] 같은 기능의 휠 패키지가 있으면 그것을 씁니다. psycopg2 는 빌드가 필요 없는 psycopg2-binary 를 따로 냅니다.
$ 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)import 이름은 그대로 psycopg2 입니다. 다만 psycopg 문서는 psycopg2-binary 를 「처음 시작하는 사람용」으로 두고, 운영에는 소스 배포를 권합니다. 남에게 배포하는 패키지의 의존성으로도 넣지 말라고 적고 있습니다. 운영 서버라면 [4] 로 갑니다.
[4] 빌드 도구를 넣습니다. 원인 줄이 바뀌는지 보며 하나씩 넣습니다. 컴파일러 하나로 끝나는 패키지도 있고, 라이브러리 헤더가 더 필요한 패키지도 있습니다. Debian 계열(공식 python:*-slim 이미지 포함)의 결과입니다.
# 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 는 gcc 만으로 빌드됐고, psycopg2 는 여전히 pg_config 를 찾았습니다. psycopg 문서대로 libpq 헤더 패키지를 넣으면 pg_config 도 같이 들어옵니다.
# 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 가 나오면 Python 헤더가 없는 것입니다. 배포판 Python 을 쓰면 python3-dev 를 넣습니다(공식 python 이미지에는 이미 들어 있어 이 시험에서는 나지 않았습니다). Docker 라면 빌드 도구는 빌드 단계에만 두고 운영 이미지로는 설치 결과만 옮깁니다.
[5] subprocess-exited-with-error 가 아니라 pip 의 ERROR: Exception: 과 긴 트레이스백으로 끝나면 다른 경우입니다. 휠이 없는 옛 numpy==1.24.4 를 Python 3.12 에 깔면 빌드 준비 단계에서 이렇게 끝났습니다.
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Cannot import 'setuptools.build_meta'이 판은 Python 3.12 용 휠이 없고, 소스의 빌드 준비부터 지금 환경에서 돌지 않았습니다. 컴파일러를 넣어 풀 문제가 아니므로 [2] 처럼 지금 Python 용 휠이 있는 판으로 고정을 올립니다.