Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

pip falls back to building SciPy from source and fails at the metadata step

Your error

Preparing metadata (pyproject.toml) ... error3 more lines it can show

Fix it fast

Most common cause, 1 of 3

The pinned SciPy is older than your Python, so no wheel exists

Raise the pin to a release that supports your Python; SciPy 1.18.1 ships wheels for CPython 3.12, 3.13, 3.14 and 3.15.

Fix
python -m pip install --upgrade "scipy>=1.18.1" numpy
# or keep the old pin with an older interpreter, e.g. for scipy 1.13:
python3.12 -m venv .venv
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

'Preparing metadata (pyproject.toml) ... error' for SciPy means pip found no wheel for your setup and began a source build, which needs C, C++ and Fortran compilers plus OpenBLAS. An old pin on a newer Python, such as scipy 1.11 on Python 3.13, usually triggers it. Install SciPy 1.18.1, with wheels for Python 3.12 to 3.15, or add the build tools.

  • Applies to SciPy 1.18.1, pip 26.3, Python 3.12 to 3.15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask pip for a wheel only, without installing. If this dry run fails for your pinned version but works without the pin, the version is the problem (cause 1). If it fails even for the latest SciPy, look at cause 2. Use cause 3 only when you really need a source build.

Run this first
python --version
python -m pip install --dry-run --only-binary=:all: "scipy==1.11.4"
python -m pip install --dry-run --only-binary=:all: scipy

Then find the line you see in this list and open its fix:

  1. 1The pinned SciPy is older than your Python, so no wheel existsThe dry run with your pin fails, the one without a pin succeeds, and your Python is newer than the last version the pinned SciPy supports
  2. 2pip or the Linux system is too old to accept the manylinux wheelsEven the unpinned dry run fails, and pip is older than 20.3 or the system's glibc is older than the 2.27 named in the wheel file names
  3. 3A source build is needed but the compilers or BLAS are missingThe log above the metadata error shows Unknown compiler(s) with gfortran first in the list, or a missing OpenBLAS or pkg-config

What does the error look like?

  • Preparing metadata (pyproject.toml) ... error
  • error: subprocess-exited-with-error
  • error: metadata-generation-failed
  • Unknown compiler(s): [['gfortran'], ['flang-new'], ['flang'], ['nvfortran'], ['pgfortran'], ['ifort'], ['ifx'], ['g95']]

Cause 1 of 3

The pinned SciPy is older than your Python, so no wheel exists

You seeThe dry run with your pin fails, the one without a pin succeeds, and your Python is newer than the last version the pinned SciPy supports

Check

SciPy publishes wheels only for the Python versions each release supports. The SciPy toolchain table lists 1.11 to 1.13 for Python below 3.13 and 1.14 to 1.16 for Python below 3.14. A requirements file that pins one of those on a newer interpreter leaves pip nothing but the source archive, and the metadata step is where that build starts and fails.

Check
grep -in "scipy" requirements*.txt pyproject.toml 2>/dev/null

Fix

Raise the pin to a release that supports your Python; SciPy 1.18.1 ships wheels for CPython 3.12, 3.13, 3.14 and 3.15. Raise NumPy with it if the old SciPy held it back. If the old version is a hard requirement, create the virtual environment with a Python inside that version's range instead.

Fix
python -m pip install --upgrade "scipy>=1.18.1" numpy
# or keep the old pin with an older interpreter, e.g. for scipy 1.13:
python3.12 -m venv .venv

Verify

pip downloads a .whl file for SciPy instead of a source archive, and the import prints the new version.

Verify
python -c "import scipy; print(scipy.__version__)"

Confirmed by docs.scipy.org

Did this fix it?

Cause 2 of 3

pip or the Linux system is too old to accept the manylinux wheels

You seeEven the unpinned dry run fails, and pip is older than 20.3 or the system's glibc is older than the 2.27 named in the wheel file names

Check

Current SciPy Linux wheels are tagged manylinux_2_27 and manylinux_2_28, which work only on glibc 2.27 or newer. The packaging specification also states that installers need pip 20.3 or later to read manylinux_x_y tags. An old system pip, or a base image with an older glibc, skips every wheel and falls back to the source build.

Check
python -m pip --version
python -c "import platform; print(platform.libc_ver())"

Fix

Upgrade pip inside the virtual environment first. If glibc is the limit, move the job to a newer base image or OS release rather than building SciPy by hand.

Fix
python -m pip install --upgrade pip
python -m pip install scipy

Verify

The dry run with --only-binary=:all: now succeeds and pip downloads a .whl file for SciPy.

Verify
python -m pip install --dry-run --only-binary=:all: scipy

Confirmed by packaging.python.org

Did this fix it?

Cause 3 of 3

A source build is needed but the compilers or BLAS are missing

You seeThe log above the metadata error shows Unknown compiler(s) with gfortran first in the list, or a missing OpenBLAS or pkg-config

Check

Building SciPy from source needs C, C++ and Fortran compilers, Python headers, BLAS and LAPACK (OpenBLAS by default) and pkg-config. Without a Fortran compiler, Meson stops at compiler detection with Unknown compiler(s), and pip reports that as a failed subprocess. The SciPy docs recommend binaries if you only want to install the package.

Check
command -v gcc g++ gfortran pkg-config

Fix

Install the system build requirements listed by SciPy for your OS, then run pip again. On macOS with Homebrew, the OpenBLAS location must be exported through PKG_CONFIG_PATH, which brew info prints.

Fix
# Debian / Ubuntu
sudo apt install -y gcc g++ gfortran libopenblas-dev liblapack-dev pkg-config python3-pip python3-dev
# macOS (Homebrew)
brew install gfortran openblas pkg-config
brew info openblas | grep PKG_CONFIG_PATH

Verify

The source build runs past the metadata step and pip completes without the subprocess error.

Verify
python -m pip install scipy --no-binary scipy

Confirmed by docs.scipy.org

Did this fix it?

How do I stop it coming back?

  • When you move a project to a new Python, check the SciPy toolchain table before raising the interpreter, and bump the SciPy pin in the same change.
  • Add pip install --only-binary=:all: to CI for scientific packages, so a missing wheel fails fast with a clear message instead of a long source build.
  • Make python -m pip install --upgrade pip the line that runs right after python -m venv in setup scripts and Dockerfiles.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.