# pip: Getting requirements to build wheel did not run successfully — how to fix it

> pip found no wheel for the package, so it started building one from source, and the package's own build script failed at the first step, while pip was asking it which build tools it needs. The real error is in the lines inside pip's box: usually a module setup.py imports but never declared (numpy, Cython, pkg_resources), a release too old for your Python, or a missing program such as pg_config. Move to a release with a wheel for your Python, or pin the Python it supports.

Source: https://livops.dev/en/guides/error-pip-getting-requirements-to-build-wheel

By Livops team, the people who build and run Livops. Updated 4 December 2026.

This is what pip prints when the step fails, here installing `psycopg2` on a machine without PostgreSQL's client tools (pip 26.0.1, shortened; the same messages are in pip 26.3's source[1][2][3]):

```text
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [34 lines of output]
      ...
      running egg_info
      ...
      Error: pg_config executable not found.
      ...
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed to build 'psycopg2' when getting requirements to build wheel
```

pip 25.2 and earlier end differently: the box is printed a second time, with `╰─> See above for output.` in place of the output[4]. The last line, `Failed to build '…' when getting requirements to build wheel`, comes from pip 25.3 and later[3]. Same failure, same fix.

This page explains what pip is doing at that moment, how to find the real error in the output, the causes from the most common, and how it differs from the better-known `Failed building wheel`. Nothing here is specific to Livops until the last section.

## What does the error mean?

When there is no wheel that fits your Python and platform, pip builds one from the source distribution (sdist). It does that in steps, and prints each one[1][10][11]:

1. **Installing build dependencies** — the packages listed in the project's `pyproject.toml` under `[build-system] requires`, installed into a temporary, isolated environment[6].
2. **Getting requirements to build wheel** — pip calls the build backend's `get_requires_for_build_wheel` hook[1]. PEP 517 defines it: the backend returns any *extra* packages it needs to build a wheel, beyond those in `pyproject.toml`[5].
3. **Preparing metadata (pyproject.toml)**.
4. **Building wheel for … (pyproject.toml)** — the actual build, with the compiler if there is one.

Your error is step 2. For the setuptools backend, answering that question means running the project's `setup.py`; the traceback in your output shows it, ending in setuptools' `run_setup`. A project with a `setup.py` and no `[build-system]` table gets setuptools as its backend, `setuptools.build_meta:__legacy__` with `setuptools>=40.8.0`[6]. So **anything `setup.py` does at the top — an import, a call to `pg_config`, a version check — runs now**, before any compiling. If it fails, the step fails.

And it runs in the isolated environment from step 1. PEP 517 says this hook runs in an environment containing only the bootstrap requirements from `pyproject.toml`[5], and pip keeps build requirements apart from your runtime environment on purpose[6]. A module you installed yourself is not there.

Before pip 25.3 some projects with only a `setup.py` went through a legacy path, where the same failure was labelled `python setup.py egg_info did not run successfully`[9]; pip 25.3 made `--use-pep517` always on[8].

## Read the real error first

pip's own lines are the same for every package. **The answer is between `[N lines of output]` and `[end of output]`**: the output of the build script, which pip collects and prints inside the box[2]. Scroll to the last line of the traceback there. A demonstration package whose `setup.py` starts with `import numpy` ends like this:

```text
        File "<string>", line 1, in <module>
      ModuleNotFoundError: No module named 'numpy'
      [end of output]
```

What that last line says decides the fix:

| Last line inside the box | Cause below |
| --- | --- |
| `ModuleNotFoundError: No module named 'numpy'` (or `Cython`, `torch`) | 1 |
| `ModuleNotFoundError: No module named 'pkg_resources'` | 2 |
| `AttributeError: module 'pkgutil' has no attribute 'ImpImporter'` | 3 |
| `No module named 'distutils'` or `'imp'` | 3 |
| `Error: pg_config executable not found.` or another missing program | 4 |

## Causes, most common first

### 1. setup.py imports a package it never declared

Older projects write `import numpy` (for `numpy.get_include()`) or `from Cython.Build import cythonize` at the top of `setup.py`, and do not list numpy or Cython in `[build-system] requires`. In the isolated build environment those modules are not installed[5][6], so the import fails. Installing numpy into your own environment first does not help, for the same reason.

**Fixes, in the order to try them:**

1. **Install a release that has a wheel for your Python.** Then pip downloads the wheel and never runs `setup.py`. Pin with `>=` to a recent release rather than an old `==`.
2. **Pin the Python the release supports** (cause 3), if you cannot move the package.
3. **Last resort: turn isolation off.** `--no-build-isolation` builds in your own environment; you must have installed every build dependency yourself, as pip does not manage them with this flag[6][7]:

```sh
pip install numpy cython setuptools wheel
pip install --no-build-isolation somepackage==1.2.3
```

### 2. setup.py imports pkg_resources

`pkg_resources` used to come with setuptools. **Setuptools 82.0.0, released on 8 February 2026, removed it**[12]. The isolated environment gets a current setuptools[6], so an old `setup.py` with `import pkg_resources` now fails at this step, whatever setuptools you have installed yourself. A newer release of the package is the fix; failing that, pip 25.3 and later accept a build constraints file that applies only to isolated build environments[22]:

```sh
echo 'setuptools<82' > build-constraints.txt
pip install --build-constraint build-constraints.txt -r requirements.txt
```

The same option can be set with the `PIP_BUILD_CONSTRAINT` environment variable[7]. The details, and the runtime side of the same error, are in [No module named 'pkg_resources'](https://livops.dev/en/guides/error-python-no-module-named-pkg-resources).

### 3. The release is older than your Python

An `==` pin names a release that has wheels only for the Pythons that existed then. On a newer Python pip finds only the sdist and runs its old `setup.py`, which may use something the newer Python removed. Python 3.12 removed `distutils`, the `imp` module, and `pkgutil.ImpImporter`[13]; Python 3.13 removed 19 more legacy modules and `lib2to3`[14].

NumPy is the well-known case. Version 1.25.2 publishes wheels for CPython 3.9, 3.10 and 3.11 only[17], and its build requirements pin `setuptools==59.2.0`[16]. The `pkg_resources` in setuptools 59.2.0 refers to `pkgutil.ImpImporter`[18], which Python 3.12 no longer has[13]. So `numpy==1.25.2` on Python 3.12 is built from source, and the build backend fails as it loads. NumPy 1.26.0 is the first release with Python 3.12 support[15]:

```text
numpy>=1.26    # instead of numpy==1.25.2, on Python 3.12
```

**Fix:** raise the pin to a release that ships a wheel for your Python, or pin the Python version the release supports. For the module errors on their own, see [No module named 'distutils'](https://livops.dev/en/guides/error-python-no-module-named-distutils) and [No module named 'imp'](https://livops.dev/en/guides/error-python-no-module-named-imp).

### 4. A system program or header is missing

Some `setup.py` files look for system tools while they are being asked for requirements. psycopg2 runs `pg_config` to find PostgreSQL's client library, and stops with `Error: pg_config executable not found.` if it is not on the `PATH`[19]; that is the output at the top of this page. Its docs list what a source build needs: a C compiler, the Python headers, the libpq headers and `pg_config`[20]. Other packages fail the same way on a missing `pkg-config`, a library, or a header.

**Fix:** use a variant that ships wheels (`psycopg2-binary`, or `psycopg[binary]` for Psycopg 3), or install the system packages in a Dockerfile. The psycopg2 case step by step: [pg_config executable not found](https://livops.dev/en/guides/error-psycopg2-pg-config-not-found).

## Getting requirements vs Failed building wheel

Both errors start the same way — no wheel fit, so pip builds from source — and they fail at different steps:

| | Getting requirements to build wheel | Failed building wheel |
| --- | --- | --- |
| Step | `get_requires_for_build_wheel`, before the build[1][5] | `build_wheel`, the build itself[11] |
| What fails | Python code in `setup.py`: an import, a version check, a tool lookup | Usually the compiler: a missing header, compiler, or Rust toolchain |
| pip's last line (25.3+) | `Failed to build '…' when getting requirements to build wheel`[3] | `error: failed-wheel-build-for-install` |

A compiler would not fix most of the first kind. The first fix for both is the same: a release, or a variant, that ships a wheel for your Python. The second error has its own page: [Failed building wheel / failed-wheel-build-for-install](https://livops.dev/en/guides/error-pip-failed-building-wheel).

## Never build from source by accident

Tell pip to refuse sdists, and a package without a matching wheel fails at once with a clear message instead of a traceback from its `setup.py`. `--only-binary :all:` disables source packages; `--prefer-binary` picks a wheel over a newer sdist[7]:

```sh
pip install --only-binary :all: -r requirements.txt
```

Both options can also go on their own line inside `requirements.txt`[21], so they apply wherever the file is installed:

```text
--prefer-binary
--only-binary numpy
numpy>=1.26
psycopg2-binary>=2.9
```

To check before a deploy, run the same install in a clean container with the Python you deploy on:

```sh
docker run --rm -v "$PWD":/app -w /app python:3.12-slim \
  pip install --only-binary :all: -r requirements.txt
```

A package that has no wheel for that Python is named in the error. Change its pin, or its variant, until the command passes.

## On Livops

- **The deploy stops as `install_failed`.** The build log shows pip's output, and a **Tip:** line at its end points at the fix. The previous version keeps running while you fix it. See [Install failed](https://livops.dev/en/docs/error-install).
- **Set the Python version in a file.** Livops runs Python 3.10 to 3.14 and reads `.python-version` and `runtime.txt`. A `.python-version` at the project root with one line pins it — the fix for cause 3 when you cannot move the package:

  ```text
  3.12
  ```

- **A second try with a compiler.** When a Python package compiles on install (`mysqlclient`, `psycopg2` and the like), Livops retries the install in an image with a compiler. That helps a build that needs a compiler; it does not help a `setup.py` that imports a module it never declared, so for causes 1 to 3 change the pin. For psycopg2 the documented way out is the variant that needs no compiling:

  ```text
  psycopg2-binary   # instead of psycopg2
  PyMySQL           # instead of mysqlclient
  ```

- **Ten minutes per build.** A large package built from source can run past the ten-minute limit and stop as `timed_out`. A wheel installs in seconds.
- **A Dockerfile, if you need system packages.** A `Dockerfile` can install them, for example `libpq-dev`. By default the `Dockerfile` is used when no framework was recognised; `"builder": "dockerfile"` in `livops.json`, read when the project is created, makes it the one that builds. See [Frameworks](https://livops.dev/en/docs/frameworks).
- **Start commands use the project's environment.** A Python start command you write yourself in **Settings → Start** begins with `.venv/bin/`, for example `.venv/bin/python main.py`.

A Python web app costs **39 credits a month**; a bot, worker or cron job **19**.

## Questions

**What does Getting requirements to build wheel mean?**

It is the step where pip, about to build a package from source, asks the package's build backend which extra packages the build needs. That is the PEP 517 hook get_requires_for_build_wheel. For a setuptools project it runs setup.py, so any import or check at the top of setup.py runs here, before anything is compiled.

**Where is the real error?**

Inside pip's box, in the lines between [N lines of output] and [end of output]. The last line of the traceback there names it, for example ModuleNotFoundError: No module named 'numpy'. Everything under the box is pip's summary and is the same for every package.

**How is it different from Failed building wheel?**

Getting requirements to build wheel fails before the compile starts, usually in Python code in setup.py. Failed building wheel fails later, in the build_wheel step, usually in a compiler. The causes overlap, the cure is often the same: install a release that ships a wheel for your Python.

**Why does pip install numpy separately and still fail?**

pip builds each package in an isolated environment that contains only the package's declared build dependencies, not what you installed. A setup.py that imports numpy without declaring it fails there. Install a release with a wheel, or, as a last resort, install the build dependencies yourself and pass --no-build-isolation.

**Is this a bug in pip?**

Almost never. pip's note says the error originates from a subprocess and is likely not a problem with pip. pip only ran the package's build script; the script failed.

**Why did it start after upgrading Python?**

A pinned release has wheels only for the Python versions that existed when it came out. On a newer Python pip falls back to the source package, and its old setup.py may rely on something the new Python removed, such as distutils, imp or pkgutil.ImpImporter in Python 3.12.

**Which Python versions does Livops run?**

Python 3.10 to 3.14. Put the version in a .python-version file at the project root, for example 3.12, to match the version your packages have wheels for.

## Sources

1. [pip 26.3 source — src/pip/_internal/distributions/sdist.py](https://raw.githubusercontent.com/pypa/pip/26.3/src/pip/_internal/distributions/sdist.py). Checked 4 December 2026.
2. [pip 26.3 source — src/pip/_internal/exceptions/build.py (InstallationSubprocessError)](https://raw.githubusercontent.com/pypa/pip/26.3/src/pip/_internal/exceptions/build.py). Checked 4 December 2026.
3. [pip 26.3 source — src/pip/_internal/exceptions/__init__.py (FailedToPrepareCandidate)](https://raw.githubusercontent.com/pypa/pip/26.3/src/pip/_internal/exceptions/__init__.py). Checked 4 December 2026.
4. [pip 25.2 source — src/pip/_internal/exceptions.py](https://raw.githubusercontent.com/pypa/pip/25.2/src/pip/_internal/exceptions.py). Checked 4 December 2026.
5. [PEP 517 — A build-system independent format for source trees](https://peps.python.org/pep-0517/). Checked 4 December 2026.
6. [pip docs — Build System Interface](https://pip.pypa.io/en/stable/reference/build-system/). Checked 4 December 2026.
7. [pip docs — pip install](https://pip.pypa.io/en/stable/cli/pip_install/). Checked 4 December 2026.
8. [pip docs — Release notes](https://pip.pypa.io/en/stable/news/). Checked 4 December 2026.
9. [pip 25.2 source — src/pip/_internal/operations/build/metadata_legacy.py](https://raw.githubusercontent.com/pypa/pip/25.2/src/pip/_internal/operations/build/metadata_legacy.py). Checked 4 December 2026.
10. [pip 26.3 source — src/pip/_internal/operations/build/metadata.py](https://raw.githubusercontent.com/pypa/pip/26.3/src/pip/_internal/operations/build/metadata.py). Checked 4 December 2026.
11. [pip 26.3 source — src/pip/_internal/operations/build/wheel.py](https://raw.githubusercontent.com/pypa/pip/26.3/src/pip/_internal/operations/build/wheel.py). Checked 4 December 2026.
12. [Setuptools docs — History (v82.0.0)](https://setuptools.pypa.io/en/latest/history.html). Checked 4 December 2026.
13. [Python docs — What's New In Python 3.12](https://docs.python.org/3/whatsnew/3.12.html). Checked 4 December 2026.
14. [Python docs — What's New In Python 3.13](https://docs.python.org/3/whatsnew/3.13.html). Checked 4 December 2026.
15. [NumPy 1.26.0 release notes](https://numpy.org/doc/stable/release/1.26.0-notes.html). Checked 4 December 2026.
16. [NumPy 1.25.2 source — pyproject.toml](https://raw.githubusercontent.com/numpy/numpy/v1.25.2/pyproject.toml). Checked 4 December 2026.
17. [PyPI JSON API — numpy 1.25.2 files](https://pypi.org/pypi/numpy/1.25.2/json). Checked 4 December 2026.
18. [Setuptools 59.2.0 source — pkg_resources/__init__.py](https://raw.githubusercontent.com/pypa/setuptools/v59.2.0/pkg_resources/__init__.py). Checked 4 December 2026.
19. [psycopg2 2.9.10 source — setup.py](https://raw.githubusercontent.com/psycopg/psycopg2/2.9.10/setup.py). Checked 4 December 2026.
20. [Psycopg 2 — Installation](https://www.psycopg.org/docs/install.html). Checked 4 December 2026.
21. [pip docs — Requirements File Format](https://pip.pypa.io/en/stable/reference/requirements-file-format/). Checked 4 December 2026.
22. [pip docs — User Guide (Build Constraints)](https://pip.pypa.io/en/stable/user_guide/). Checked 4 December 2026.
