Introduction
PEP 517 introduced the [build-system] table in pyproject.toml to specify build dependencies and the build backend. When pip tries to build a package and the specified backend (e.g., setuptools.build_meta, hatchling.build) is not available, the installation fails. This happens when the requires list is incomplete, the backend package is not installed, or the backend name is misspelled.
Symptoms
ModuleNotFoundError: No module named 'hatchling'Backend 'setuptools.build_meta' is not available. Please ensure you have the latest setuptools installed.ERROR: Could not build wheels for package, which is required to install pyproject.toml-based projectsBuild backend 'flit_core.buildapi' not found
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
ModuleNotFoundError: No module named 'hatchling'Common Causes
pyproject.tomllists a backend inrequiresthat pip cannot fetch- Typo in build-backend name (e.g.,
setuptools.buildmetainstead ofsetuptools.build_meta) - Using a backend not installed in the build environment
- Network issues preventing pip from downloading build dependencies
- Isolated build environment cannot reach PyPI
Step-by-Step Fix
- 1.Verify the build backend configuration:
- 2.```toml
- 3.# Check pyproject.toml
- 4.[build-system]
- 5.requires = ["setuptools>=68.0", "wheel"]
- 6.build-backend = "setuptools.build_meta"
- 7.
` - 8.Install the build backend manually:
- 9.```bash
- 10.# For setuptools
- 11.pip install "setuptools>=68.0" wheel
# For hatch pip install hatchling hatch-vcs
# For poetry pip install poetry-core
# For flit pip install flit_core
# For pdm pip install pdm-backend ```
- 1.Build without isolation to use already-installed backends:
- 2.```bash
- 3.# Disable build isolation - uses backends from current environment
- 4.pip install --no-build-isolation .
# Useful in CI where you pre-install build tools pip install setuptools>=68.0 wheel hatchling pip install --no-build-isolation -e . ```
- 1.Fix common backend configuration errors:
- 2.```toml
- 3.# WRONG - typo in backend name
- 4.[build-system]
- 5.build-backend = "setuptools.buildmeta" # Wrong!
# CORRECT [build-system] build-backend = "setuptools.build_meta"
# WRONG - missing the backend entirely [build-system] requires = ["setuptools"] # build-backend is required by PEP 517
# CORRECT - always specify both [build-system] requires = ["setuptools>=68.0"] build-backend = "setuptools.build_meta" ```
- 1.Configure pip to use a custom index for build dependencies:
- 2.```bash
- 3.# For corporate environments with internal PyPI mirror
- 4.pip install --index-url https://pypi.company.com/simple .
# Or set environment variable export PIP_INDEX_URL=https://pypi.company.com/simple pip install . ```
- 1.Pre-build wheels to avoid build-time backend issues:
- 2.```bash
- 3.# Build the wheel first with explicit backend
- 4.pip install build
- 5.python -m build --wheel
# Then install the wheel directly pip install dist/mypackage-1.0.0-py3-none-any.whl ```
Prevention
- Use well-known backends:
setuptools,hatchling,poetry-core,flit_core - Pin backend versions in
requiresto avoid breaking changes - Test package installation in a clean virtual environment
- Use
pip install --no-build-isolationin CI for faster, more reliable builds - Include build dependencies in Docker image layers:
- ```dockerfile
- RUN pip install --no-cache-dir "setuptools>=68.0" "wheel" "build"
`- Validate pyproject.toml with
validate-pyproject: - ```bash
- pip install validate-pyproject
- validate-pyproject pyproject.toml
`