Skip to content
Latchkey

Dockerfile RUN pip install exit code 1 in CI

pip exited non-zero inside a RUN step, so the whole build step fails with exit code 1. The real reason is in the pip output above the summary line: usually no network to PyPI, or a source build that needs a compiler the image lacks.

What this error means

A RUN pip install step ends with "process \"/bin/sh -c pip install -r requirements.txt\" did not complete successfully: exit code: 1" after pip prints a network or build error.

docker build
ERROR: failed to solve: process "/bin/sh -c pip install -r requirements.txt"
did not complete successfully: exit code: 1

Common causes

No egress or proxy for PyPI inside the build

The build network cannot reach PyPI, so pip fails with a name-resolution or timeout error and exits 1.

A source build with no compiler or headers

A package with no wheel for the platform compiles from source and needs build tools or -dev headers a slim image does not include.

How to fix it

Add the build dependencies pip needs

Install a compiler and headers before pip when a source build is unavoidable.

Dockerfile
RUN apt-get update \
 && apt-get install -y --no-install-recommends build-essential python3-dev \
 && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir -r requirements.txt

Configure the index or prefer wheels

  1. Point pip at an internal mirror with PIP_INDEX_URL when egress is restricted.
  2. Force binary wheels so no compiler is needed where possible.
  3. Ensure the build has DNS and egress to the index.
Dockerfile
RUN pip install --only-binary=:all: -r requirements.txt

How to prevent it

  • Give the build network access to the package index it needs.
  • Install -dev packages and a compiler for unavoidable source builds.
  • Prefer wheels so the build never invokes a compiler.

Frequently asked questions

What causes ""pip install ... did not complete successfully: exit code: 1""?
The build network cannot reach PyPI, so pip fails with a name-resolution or timeout error and exits 1.
How do I fix "pip install ... did not complete successfully: exit code: 1"?
Install a compiler and headers before pip when a source build is unavoidable.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card