Skip to content
Latchkey

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 --sdist

Common 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

OptionDoes
--wheel, -wBuild only the wheel
--sdist, -sBuild only the source distribution
--no-isolation, -nUse the current env, no isolated build
--outdir, -o DIRWrite artifacts to DIR

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →