Setuptools
Setuptools is Python's original and most established build backend for packaging, distributing, and installing Python packages, with full support for C/C++ extension modules, entry points, and PEP 517/660 editable installs. Current version is 82.0.1 (released Feb 2026). The project ships frequently — multiple major versions per month — and has a history of disruptive but well-warned breaking changes. Requires Python >=3.9 as of v75.4.0.
Warnings
- breaking pkg_resources was fully removed in setuptools 81.0.0 (released Feb 8 2026). Any code or dependency doing 'import pkg_resources' will raise ModuleNotFoundError on setuptools >= 81.
- breaking setup.cfg keys using hyphens (e.g. 'description-file', 'long-description') raise InvalidConfigError in setuptools >= 78. This was a deprecation since 2021 that became an error in v78.
- breaking project.license as a TOML table (e.g. license = {text = 'MIT'}) is deprecated as of setuptools 77 in favour of a plain SPDX string (license = 'MIT'). The table form will eventually be rejected.
- deprecated Running 'python setup.py install', 'python setup.py develop', 'python setup.py test', and other direct setup.py CLI invocations are deprecated and being removed incrementally. 'setup.py develop' now defers to pip internally.
- breaking Python 3.8 support was dropped in setuptools 75.4.0. The last version supporting Python 3.8 is 75.3.x (actively maintained as a security-only branch).
- gotcha Do NOT add 'wheel' to build-system.requires in pyproject.toml. This was historically recommended but is now unnecessary and actively discouraged by the official docs.
- gotcha Static analysis tools (mypy, pyright, pylint) may not work correctly when setuptools uses an import-hook-based editable install (the default). This is a known limitation of the compat editable mode.
Install
-
pip install setuptools -
pip install "setuptools>=61.0"
Imports
- setup
from setuptools import setup
- find_packages
from setuptools import find_packages
- find_namespace_packages
from setuptools import find_namespace_packages
- Extension
from setuptools import Extension
- version (runtime metadata)
from importlib.metadata import version
- entry_points (runtime)
from importlib.metadata import entry_points; eps = entry_points(group='my.group')
- build_meta (build backend)
build-backend = "setuptools.build_meta" # in pyproject.toml [build-system]
Quickstart
# pyproject.toml (place in your project root — no setup.py needed)
# [build-system]
# requires = ["setuptools>=61"]
# build-backend = "setuptools.build_meta"
#
# [project]
# name = "mypackage"
# version = "0.1.0"
# description = "My package"
# requires-python = ">=3.9"
# license = "MIT" # PEP 639 SPDX string (setuptools >= 77)
# dependencies = ["requests>=2.25"]
#
# [project.scripts]
# my-cli = "mypackage.cli:main"
# --- Programmatic use (setup.py, still valid as config file) ---
from setuptools import setup, find_packages
setup(
name="mypackage",
version="0.1.0",
packages=find_packages(where="src"),
package_dir={"": "src"},
python_requires=">=3.9",
install_requires=["requests>=2.25"],
)
# --- Runtime metadata (replaces pkg_resources) ---
from importlib.metadata import version, entry_points
pkg_version = version("mypackage")
eps = entry_points(group="console_scripts")