Skip to main content

canibuild

Find the dependencies in your lockfile that will fail to build from source, before you run pip install, uv sync or poetry install. For each one, canibuild tells you why and gives you the one-line fix for your tool.

setuptools 82 removed pkg_resources. Every sdist whose setup.py still imports it now fails in a fresh isolated build with ModuleNotFoundError: No module named 'pkg_resources', and pinning setuptools in your own environment doesn't help, because the build gets its own, newest setuptools. canibuild reads your lockfile, works out which packages have no wheel for your Python and platform, opens their sdists without running them, and reports what will break.

$ pip install canibuild
$ canibuild uv.lock

Example

This is the uv.lock of a public project (geosp/mcp-bible at 904dc66), whose uv sync broke on flatdict 4.0.1:

$ canibuild check uv.lock --python 3.12 --platform linux-x86_64
canibuild: uv.lock for CPython 3.12 on linux-x86_64
81 packages checked, 1 builds from source, 1 will fail, 0 may fail

SEVERITY  PACKAGE   VERSION  RULE           PROBLEM
ERROR     flatdict  4.0.1    pkg-resources  setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1

flatdict 4.0.1: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
  at setup.py:1: import pkg_resources
  fix (any): Upgrade flatdict to 4.1.0, the first newer release with a wheel for this target
      uv lock --upgrade-package 'flatdict>=4.1.0'
  fix (uv): Constrain setuptools in flatdict's build (pyproject.toml)
      [tool.uv.extra-build-dependencies]
      flatdict = ["setuptools<82"]
  fix (uv): Or constrain it for every build (pyproject.toml)
      [tool.uv]
      build-constraint-dependencies = ["setuptools<82"]

Not checked: 1 (mcp-weather: git source, not checked)

The run took under a second with a warm cache. It exits with status 1, so it can gate CI.

For a requirements.txt that pins openai-whisper==20231117, which has no wheels at all:

$ canibuild requirements.txt --python 3.12 --platform linux-x86_64
...
openai-whisper 20231117: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
  at setup.py:5: import pkg_resources
  fix (any): Upgrade openai-whisper to 20250625, the first newer release whose sdist has none of these problems
      openai-whisper>=20250625  # in requirements
  fix (uv pip): Pass a build constraints file
      echo 'setuptools<82' > build-constraints.txt
      uv pip install -b build-constraints.txt -r requirements.txt
  fix (pip): Pass a build constraints file (pip 25.3+)
      echo 'setuptools<82' > build-constraints.txt
      pip install --build-constraint build-constraints.txt -r requirements.txt
  fix (pip): pip older than 25.3: use PIP_CONSTRAINT (ignored for builds since pip 26.2)
      echo 'setuptools<82' > build-constraints.txt
      PIP_CONSTRAINT=build-constraints.txt pip install -r requirements.txt

Builds from source with no known problem: deepspeed 0.20.2 (compiles native code), langid 1.1.6, textgrid 1.6.1

What it checks

canibuild only looks at packages that will be built from source: those with no wheel matching the target interpreter and platform. For each of them it downloads the sdist (cached), reads pyproject.toml, setup.py, setup.cfg and the local modules setup.py imports, and parses them with ast. It never runs code from a package.

Rule Fails when
pkg-resources setup.py (or a local module it imports) imports pkg_resources and the build would get setuptools 82 or newer
build-tool-needs-pkg-resources setup_requires or build-system.requires pins setuptools-scm older than 6.3 or pbr older than 7.0, which import pkg_resources themselves
setuptools-easy-install, setuptools-test-command, setuptools-dep-util, setuptools-use-2to3 setup.py uses a setuptools API that was removed (in 80.3, 72, 70 and 58) and the build gets a newer setuptools
numpy-distutils setup.py imports numpy.distutils, which doesn't exist on Python 3.12+ or with NumPy 2
distutils setup.py imports distutils on Python 3.12+ and setuptools isn't in the build
missing-build-requires setup.py imports a module at top level (such as torch or numpy) that the sdist doesn't declare in build-system.requires, so the isolated build can't import it
no-installable-file there is no wheel for the target and no sdist
c-api-removed Python 3.15+: a C or C++ source calls a function that Python 3.15 removed, such as PyWeakref_GetObject or Py_GetPrefix, outside any version check
free-threading-limited-api free-threaded 3.13t or 3.14t: the build enables the limited C API (py_limited_api in setup.cfg or setup.py, or Py_LIMITED_API defined in a source file or define_macros), which these builds reject

An import inside a try: ... except ImportError is ignored. An import inside a function is reported as a warning, since it fails only if that code runs during the build. An import in a branch that a pip/uv build never takes is ignored too: a test on sys.argv for a command other than the ones setuptools' build backend runs (egg_info, dist_info, bdist_wheel, sdist, editable_wheel), directly or through a helper like pygame's consume_arg("cython"), or a check for a file the sdist doesn't contain (os.path.exists, glob.glob, Path.exists()), followed through simple flag variables and through paths built from the setup script's own location (HERE = os.path.dirname(os.path.abspath(__file__)), os.path.join(HERE, ...), Path(__file__).parent / ...). pygame 2.6.1, for example, only imports Cython when its generated C files are missing, and msilib for bdist_msi. When a condition can't be worked out, the import is reported as before. Packages that build from source with no known problem are listed as such, with a note when they compile native code. When such a package has compiled wheels, just none for the target (say, wheels up to cp313 but not cp315 or cp314t), it is reported as a no-wheel-for-python warning, since the build is probably unexpected and needs a compiler; the fix names the first newer release with a matching wheel.

New Python versions and free-threaded builds

Pass --python 3.15 to check a new Python before its wheels are out, and --python 3.14t (or cp314t) for the free-threaded build. Wheel matching follows the interpreter: abi3 wheels don't install on free-threaded 3.13t and 3.14t, and on 3.15t only abi3t wheels (PEP 803) do.

Two checks read the C sources of packages that would be built:

  • c-api-removed looks for calls to the functions listed under "Removed C APIs" in What's New in Python 3.15. With GCC 14+ or Clang 16+ the build fails with an implicit declaration error; older compilers build a module that fails on import. Calls are skipped when they sit inside an #if on PY_VERSION_HEX, PY_MINOR_VERSION, Py_LIMITED_API, PYPY_VERSION or a Cython switch (or a macro defined from one of those), when the package defines the name itself (a compat header), and under tests/, docs/ and examples/. Comments and strings are ignored.
  • free-threading-limited-api flags builds that turn on the limited API for 3.13t or 3.14t. CPython 3.13 and 3.14 stop the compile with #error "The limited API is not currently supported in the free-threaded build", and setuptools refuses py_limited_api there. Settings behind a Py_GIL_DISABLED check are not reported.

For example, pygame==2.6.1 on 3.15 (it calls PyWeakref_GetObject in src_c/surface.c) and pycryptodome==3.19.0 on 3.14t (py-limited-api = cp35 in setup.cfg); --verify confirms both.

Git, path and URL dependencies

Dependencies that installers fetch directly are always built from source, so canibuild checks them with the same rules:

  • git (source = { git = ... } in uv.lock, vcs in pylock.toml, name @ git+https://...@rev or -e git+... in requirements): fetched with git fetch --depth 1 at the locked commit (or the branch or tag the requirement names), with hooks disabled and no submodules, then read like an sdist. Checkouts of a pinned commit are cached. When the requirement names a branch or tag, or nothing, the report says which commit was checked.
  • path (directory, path and non-root editable sources, ./dir, file: URLs): the local directory or archive is read in place, relative to the lockfile.
  • URL (source = { url = ... }, archive in pylock.toml, name @ https://...): sdists are downloaded and read; a wheel URL is only checked against the target's tags.

Findings for these show where the code came from, and --verify builds them from the same reference (name @ git+URL@commit), so a git build needs access to that git host.

Forcing or forbidding source builds

Some projects build certain packages from source on purpose, or forbid source builds entirely. canibuild reads those settings and checks accordingly:

Setting Where canibuild reads it Effect
no-binary [tool.uv] no-binary = true / no-binary-package = [...] (pyproject.toml or uv.toml next to uv.lock); [tool.uv.pip] no-binary = [...]; --no-binary lines in requirements files; --no-binary PKGS on the command line Wheels are ignored for those packages, so their sdists are inspected even when a wheel exists.
no-build [tool.uv] no-build / no-build-package; [tool.uv.pip] no-build and only-binary; --only-binary lines in requirements files; --no-build PKGS on the command line A package with no matching wheel is an error (no-build), with the first newer release that has a wheel as the fix.

PKGS is a comma-separated list of names or :all:; requirements files also accept :none:, and later lines override earlier ones as in pip. A package named explicitly in one setting beats :all: in the other. The report shows the settings in effect and where they came from:

$ canibuild examples/broken/requirements.txt --python 3.12 --no-build :all:
canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
2 packages checked, 0 build from source, 1 will fail, 0 may fail
build settings: no-build: :all: (from --no-build)

The setuptools version a build would get is worked out from the sdist's own build-system.requires (or pip's and uv's default of setuptools>=40.8.0 when it has none) and the setuptools releases on PyPI, so a package that already caps setuptools<82 isn't flagged.

Fixes

Every finding comes with fixes for the tool that matches your lockfile (uv.lock gets uv, pylock.toml and requirements files get pip and uv pip). Pass --tool to choose (uv, uv-pip, pip, poetry or all).

Tool Fix for a build that needs setuptools<82
uv [tool.uv.extra-build-dependencies] pkg = ["setuptools<82"], or [tool.uv] build-constraint-dependencies = ["setuptools<82"]
uv pip uv pip install -b build-constraints.txt ...
pip 25.3+ pip install --build-constraint build-constraints.txt ... (or PIP_BUILD_CONSTRAINT)
pip older than 25.3 PIP_CONSTRAINT=build-constraints.txt pip install ... (pip 26.2 stopped applying this to builds)
Poetry 2.3+ [tool.poetry.build-constraints] pkg = { setuptools = "<82" }, then poetry lock

Each of these was checked against flatdict==4.0.1 with uv 0.13, pip 26.3 and 25.1, and Poetry 2.5: the install fails without the fix and succeeds with it. When a newer release of the package has a wheel for your target, or an sdist without the problem, canibuild suggests upgrading to the oldest such release first.

Note that uv's own hint for this error suggests adding pkg_resources to extra-build-dependencies. That can't work: pkg_resources isn't a package on PyPI.

Confirming a prediction with a real build

The checks above are static. --verify goes one step further: for every package with an error or warning, it builds that sdist in a throwaway environment with uv (uv pip install --no-deps --no-binary PKG, from PyPI only, isolated from your uv config), and records whether the build really fails the way canibuild said. When the finding has a build constraint such as setuptools<82, it builds once more with that constraint to show whether the fix works. For a missing build requirement such as torch, it builds once more with the requirement added through uv's extra-build-dependencies, and shows the next error if the build still fails (for flash-attn that is CUDA_HOME not being set).

$ canibuild examples/broken/requirements.txt --python 3.12 --verify --tool uv-pip
canibuild: building flatdict 4.0.1 to verify...
canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
2 packages checked, 1 builds from source, 1 will fail, 0 may fail, 1 confirmed by a real build

SEVERITY  PACKAGE   VERSION  RULE           PROBLEM
ERROR     flatdict  4.0.1    pkg-resources  setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1

flatdict 4.0.1: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
  at setup.py:1: import pkg_resources
  verified: confirmed (ModuleNotFoundError: No module named 'pkg_resources')
  with setuptools<82 in the build: builds
  fix (any): Upgrade flatdict to 4.1.0, the first newer release with a wheel for this target
      flatdict>=4.1.0  # in requirements
  fix (uv pip): Pass a build constraints file
      echo 'setuptools<82' > build-constraints.txt
      uv pip install -b build-constraints.txt -r requirements.txt

Each finding gets one of these results:

Result Meaning
confirmed The build failed with the error the finding predicts.
fails-differently The build failed, but not with that error. The last error line is shown.
refuted The build succeeded. The finding no longer counts toward --fail-on.
timeout No result within --verify-timeout seconds (default 900).
skipped uv isn't installed, the target platform isn't this machine (the detail names both), or uv couldn't create an environment for the target Python.
builds For no-wheel-for-python: the sdist built on the target Python. It stays a warning, since the install still needs a compiler.
builds-without-extension For no-wheel-for-python: the build finished, but the installed package has no compiled modules although its wheels for other Pythons do. The build's reason is shown when it printed one, such as a missing header followed by "falling back to pure Python".
fails For no-wheel-for-python: the source build failed; the first error it printed is shown, and the finding becomes an error.

For example, msgpack 1.1.0 and numpy 1.26.4 build from source on 3.15 but fail on free-threaded 3.14t (unknown type name '__pyx_vectorcallfunc' and 'PyObject' has no member named 'ob_refcnt'). PyYAML 6.0.1 on 3.15 without the libyaml headers installs, but as pure Python:

pyyaml 6.0.1: has compiled wheels for cp36m, cp37m, cp38, cp39, cp310, cp311, cp312 but none for CPython 3.15 on linux-x86_64; pip/uv will build it from the sdist
  verified: builds-without-extension (yaml/_yaml.h:2:10: fatal error: yaml.h: No such file or directory; Error compiling module, falling back to pure Python (installed with no compiled modules, though its wheels for other Pythons have them))

A package that builds some of its extensions and skips others still shows as builds.

Builds run in parallel, --verify-jobs at a time (default: half the CPUs, at most 4); output keeps the report's order whichever build finishes first. Large native packages can take minutes. uv may download the target Python if it isn't installed. Missing-file and not-checked findings are not built.

Tested on real lockfiles

canibuild was run on 13 lockfiles from public repositories (5 uv.lock, 8 requirements files). Then every sdist those lockfiles would build was actually built, in a fresh environment with uv pip install --no-deps, to see which builds really fail.

  • 26 packages would build from source (23 distinct package versions).
  • 10 of them really fail: flatdict 4.0.1 (2 lockfiles), openai-whisper 20231117 (2) and 20240930 (2), salib 1.3.12 and mmcv 2.2.0 import pkg_resources; flash-attn 2.8.3.post2 imports torch without declaring it; faiss-cpu 1.7.4 has no wheel for Python 3.12 and no sdist.
  • canibuild reported all 10 with the right cause, and none of the 16 that built fine.
  • With the suggested setuptools<82 build constraint, all five distinct pkg_resources failures build. jproperties 2.1.2 built from source (its setup_requires pins setuptools-scm 3.x) is caught by build-tool-needs-pkg-resources, fails for real, and builds with the same constraint.

Running the same lockfiles with --verify confirmed all 9 build failures it could build (faiss-cpu has nothing to build), and the setuptools<82 constraint made all 8 pkg_resources cases build.

The lockfiles, their commits and the per-package results are in docs/validation.md.

Usage

canibuild [check] LOCKFILE... [--python X.Y] [--platform P] [--format text|json]
                              [--fail-on error|warning|never] [--tool TOOL] [--jobs N]
                              [--no-binary PKGS] [--no-build PKGS]
                              [--verify] [--verify-timeout SECONDS] [--verify-jobs N]
                              [--json-report PATH]
                              [--cache-dir DIR] [--no-cache] [-v]
  • LOCKFILE: one or more of uv.lock, pylock.toml (or pylock.NAME.toml), or a requirements file. Requirements files may include other files with -r. Unpinned requirements are checked at the newest release that matches and supports the target Python.
  • --python: the target Python, such as 3.12, 3.15, or 3.14t for a free-threaded build. Defaults to the running interpreter, or to the oldest version a uv.lock or pylock.toml allows when the running one is outside its requires-python.
  • --platform: linux-x86_64, linux-aarch64, musllinux-x86_64, musllinux-aarch64, macos-arm64, macos-x86_64, windows-amd64, windows-arm64, windows-x86, or a raw platform tag such as manylinux_2_28_x86_64. Defaults to the current machine.
  • --format json: machine-readable output with every finding and fix (a list when you pass several lockfiles).
  • --json-report PATH: also write the JSON report, always as a list, while printing text.
  • --no-binary, --no-build: force or forbid source builds (see above); added to the settings found in the project's files.
  • --verify, --verify-timeout, --verify-jobs: build flagged sdists to confirm the findings (see above).
  • --fail-on: exit with 1 on errors (the default), on warnings too, or never. With several lockfiles, the run fails if any of them does. Usage errors and unreadable lockfiles exit with 2.

Downloaded sdists are cached in the user cache directory (~/.cache/canibuild on Linux, or $CANIBUILD_CACHE_DIR).

GitHub Action

- uses: actions/checkout@v4
- uses: driftwright/canibuild@v0.6.0
  with:
    lockfiles: uv.lock          # default: every uv.lock, pylock*.toml, requirements*.txt
    python: "3.12"              # default: as for --python below
    # platform: linux-x86_64    # default: the runner
    # fail-on: error            # error, warning or never
    # tool: uv                  # tools to show fixes for
    # no-binary: ":all:"        # build these from source even when a wheel exists
    # no-build: numpy           # these must install from a wheel
    # verify: "true"            # build flagged sdists to confirm the findings
    # verify-jobs: "2"          # builds at once (default: half the CPUs, at most 4)

The action installs uv, runs canibuild with the code of the tag you pinned (or the PyPI release given in version), prints the report, adds it to the job summary, and fails the step when something will fail to build. The JSON report's path is in the report output. Check several targets with a matrix over python and platform; verify only builds when platform is the runner's own.

pre-commit

repos:
  - repo: https://github.com/driftwright/canibuild
    rev: v0.6.0
    hooks:
      - id: canibuild
        # args: [--python, "3.12"]

The hook runs when uv.lock, a pylock*.toml or a requirements*.txt changes, and needs network access to PyPI.

Limits

  • Versions from other indexes (such as torch==2.1.2+cu121) and non-git version control (Mercurial, Subversion, Bazaar) are listed as not checked. Private git repositories work only if git can reach them without a prompt.
  • The checks are static. A setup.py that fails for a reason not in the table above, or that needs a compiler or system library you don't have, isn't caught. The C checks only cover the removed 3.15 functions and the limited-API conflict; other free-threading problems (thread safety, Py_mod_gil) and C files over 512 KiB are not inspected.
  • Requirements files are not resolved: only the packages they list are checked, not their dependencies. Use a lockfile (uv.lock, pylock.toml, or pip-compile output) for the full tree.

License

MIT

Metadata

Release files for canibuild 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for canibuild 0.6.0
File Size Uploaded Provenance Actions
canibuild-0.6.0.tar.gz 117.2 kB Without provenance Details for canibuild-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for canibuild 0.6.0
File Interpreter ABI Platform Actions
canibuild-0.6.0-py3-none-any.whl Python 3 none any Details for canibuild-0.6.0-py3-none-any.whl

Total release size: 185.3 kB

Release files / canibuild-0.6.0.tar.gz

Download URL canibuild-0.6.0.tar.gz
Size 117.2 kB
Tags Source
SHA-256 checksum
How to use checksums
675a14a0d0059d78a7d3230ab302bc1c26eb3f8fba6dfa624097bb6e3223087b
BLAKE2b-256 checksum
How to use checksums
014d987632629fb1ff7e142530e9a40709b3594b637da606f4c7a4e03fe6e73b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / canibuild-0.6.0-py3-none-any.whl

Download URL canibuild-0.6.0-py3-none-any.whl
Size 68.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51c586dea64417f6a10a7b2ab2fa886bdae425a0d7de0eeb0efb1836759dc148
BLAKE2b-256 checksum
How to use checksums
8cf79770daaf15bf4eb06b00cd4f03cab70980ae1c01a8fe9a71bd10e222b835
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for canibuild 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page