python -m build: Build Wheels and Sdists
The standard, frontend-agnostic way to build distributions.
python -m build (the pypa/build tool) builds an sdist and a wheel in an isolated environment using the backend declared in pyproject.toml. It is the modern replacement for "setup.py sdist bdist_wheel".
What it does
Reads [build-system] from pyproject.toml, creates an isolated build environment, and produces a source distribution and a wheel in dist/. Requires the "build" package to be installed.
Common usage
Terminal
python -m pip install build
python -m build
python -m build --wheel
python -m build --sdistCommon CI error: missing build-system
Without a [build-system] table, build cannot determine a backend and fails. Declare requires and build-backend in pyproject.toml.
pyproject.toml
# Failure:
# ERROR Missing dependencies / no build-backend
# Fix:
[build-system]
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"Options
| Option | Does |
|---|---|
| --wheel, -w | Build only the wheel |
| --sdist, -s | Build only the source distribution |
| --no-isolation, -n | Use the current env, no isolated build |
| --outdir, -o DIR | Write artifacts to DIR |
Related guides
python -m twine: Upload Packages to PyPIHow python -m twine uploads built distributions to PyPI or a private index, the check command to catch metada…
pip wheel: Build Wheels for Your DependenciesHow pip wheel builds wheel archives for a project and its dependencies, why CI uses it to pre-build a wheelho…
poetry build: Build Wheel and SdistHow poetry build produces a wheel and sdist into dist/, the --format flag, and the project-metadata errors it…