PEP 517 Build Frontend
pep517 provides low-level wrappers to interact with Python package build backends that implement PEP 517 hooks. It is primarily used by build frontends like `pip` and `build` to orchestrate the build process (e.g., building source distributions, wheels). The current stable version is 0.13.1, and releases occur as needed to address issues or align with packaging standards, typically not on a strict cadence.
Common errors
-
ERROR: Could not build wheels for X which use PEP 517 and cannot be installed directly
cause This generic error indicates a build failure for a package using PEP 517, often due to an outdated `pip` version, missing system-level build tools (like C compilers or development headers), or the absence of pre-built wheels for your specific Python version and operating system.fixUpgrade `pip` (`python -m pip install --upgrade pip`), install necessary system dependencies (e.g., `sudo apt-get install python3-dev build-essential` on Debian/Ubuntu, or specific library development packages as indicated in the verbose error log), or ensure your Python version is supported by the package. As a last resort, `pip install --no-use-pep517 <package-name>` might work if the issue is a package's improper PEP 517 support, though this is generally discouraged. -
ModuleNotFoundError: No module named 'Y'
cause This occurs when a build dependency required by the package's build backend (e.g., `setuptools`, `packaging`, `wheel`, or a system tool like `cmake`, or even `distutils` in Python 3.12+) is not found in the isolated build environment managed by `pep517`. For `distutils`, this is particularly common in Python 3.12+ where it was removed.fixFor package developers, ensure all build dependencies are correctly listed in the `build-system.requires` section of `pyproject.toml`. For users, if upgrading `pip` doesn't resolve it, the package might need to be updated to a version compatible with your Python (e.g., NumPy 1.26+ for Python 3.12+ to address `distutils` removal). You might also need to install missing system-level build tools if they are the root cause. -
ERROR: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully.
cause This indicates a failure during the initial phase of the PEP 517 build process where the build backend attempts to determine its own build requirements. The underlying cause is typically detailed in the output immediately preceding this error, often a `ModuleNotFoundError`, a `SyntaxError` in a `setup.py` (if the backend uses it), or a missing system dependency.fixCarefully examine the detailed error messages in the output preceding this line to identify the specific failure. This will guide you to install missing Python packages, required system-level tools (like compilers or native libraries), or report the issue to the package maintainers if the `pyproject.toml` configuration is incorrect. -
AttributeError: 'InstallRequirement' object has no attribute 'use_pep517'
cause This specific error arises when a tool (such as `pip-tools`) that relies on `pip`'s internal APIs encounters a newer version of `pip` (e.g., pip 25.3+) where the `use_pep517` attribute of `InstallRequirement` has been removed. This signifies an incompatibility between the tool and the `pip` version.fixDowngrade `pip` to a version compatible with the tool (e.g., `pip install "pip<25.3"` if `pip-tools` is the affected utility) or upgrade the tool itself to a version that supports the newer `pip` APIs.
Warnings
- gotcha pep517 is a low-level library designed for build *frontends* (like `pip` or `build`). It is generally not intended for direct use by end-users looking to simply build a Python package.
- gotcha The `build-backend` specified in `pyproject.toml` must be importable in the Python environment where `pep517` is executed. Incorrect `backend_path` or an uninstalled backend will lead to `BackendUnavailable` or `BackendFailed` exceptions.
- gotcha The `config_settings` dictionary passed to backend hooks (e.g., `build_wheel`, `get_requires_for_build_wheel`) is specific to each build backend. There is no universal standard for these settings, and passing unsupported options can lead to unexpected behavior or errors.
Install
-
pip install pep517
Imports
- Pep517HookCaller
from pep517.wrappers import Pep517HookCaller
- BuildBackendException
from pep517.wrappers import BuildBackendException
Quickstart
import os
import tempfile
from pathlib import Path
import shutil
from pep517.wrappers import Pep517HookCaller, BuildBackendException
# Create a dummy project directory with a pyproject.toml
# In a real scenario, this would be an existing project.
project_dir = Path(tempfile.mkdtemp())
try:
(project_dir / "pyproject.toml").write_text("""
[build-system]
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"
""")
(project_dir / "src").mkdir()
(project_dir / "src" / "__init__.py").write_text("")
(project_dir / "src" / "my_module.py").write_text("VERSION = '0.1.0'")
# Instantiate a Pep517HookCaller to interact with the backend
# For setuptools.build_meta, backend_path is typically empty,
# meaning it's expected to be importable directly.
caller = Pep517HookCaller(
source_dir=project_dir,
build_backend="setuptools.build_meta",
backend_path=[]
)
# Example: Get build requirements for a wheel
# config_settings can be an empty dict if no specific settings are needed
requires = caller.get_requires_for_build_wheel(config_settings={})
print(f"Build requires for wheel: {requires}")
except BuildBackendException as e:
print(f"Backend error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
# Clean up temporary directory
if project_dir.exists():
shutil.rmtree(project_dir)