Skip to content
Latchkey

Python "ValueError: numpy.dtype size changed" (binary incompatibility) in CI

A compiled extension reads NumPy's internal dtype struct, and the struct size it was built with no longer matches the installed NumPy. NumPy warns that this signals binary incompatibility, then the import or call fails.

What this error means

Importing or using a package raises "ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject".

python
ValueError: numpy.dtype size changed, may indicate binary incompatibility.
Expected 96 from C header, got 88 from PyObject

Common causes

Extension built against a newer NumPy than installed

The wheel was compiled with a NumPy whose dtype struct is larger; the older installed NumPy reports a smaller size, so they disagree.

Mixed NumPy versions from layered installs

Caching or a second install step left a NumPy that does not match what the binary dependents were built against.

How to fix it

Reinstall with a consistent NumPy

  1. Pin NumPy and the failing package to compatible versions.
  2. Force-reinstall so the binaries are rebuilt or refetched against that NumPy.
  3. Recompile the lockfile to keep them aligned.
Terminal
pip install --force-reinstall "numpy==1.26.4" pandas scikit-learn

Use build-time NumPy pinning for source builds

If you build extensions from source, build against the oldest supported NumPy so the ABI is forward-compatible.

pyproject.toml
[build-system]
requires = ["setuptools", "wheel", "numpy>=2.0.0", "Cython"]

How to prevent it

  • Keep NumPy and its compiled dependents pinned together.
  • Avoid layering a second NumPy install over an existing one in CI.
  • Build extensions against a compatible NumPy ABI baseline.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →