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".
ValueError: numpy.dtype size changed, may indicate binary incompatibility.
Expected 96 from C header, got 88 from PyObjectCommon 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
- Pin NumPy and the failing package to compatible versions.
- Force-reinstall so the binaries are rebuilt or refetched against that NumPy.
- Recompile the lockfile to keep them aligned.
pip install --force-reinstall "numpy==1.26.4" pandas scikit-learnUse 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.
[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.