Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
AI and LLM integration

A compiled package or TensorFlow will not load with the installed NumPy

Your error

A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.0 as it may crash.4 more lines it can show

Fix it fast

Most common cause, 1 of 4

NumPy 2 is installed under TensorFlow 2.17 or older

Upgrade TensorFlow, which needs Python 3.10 or newer from 2.21 on.

Fix
python -m pip install -U "tensorflow==2.21.*"
# or, to stay on an old TensorFlow:
python -m pip install "tensorflow==2.17.1" "numpy<2"
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

ImportError: numpy.core.multiarray failed to import, and TensorFlow's SystemError that _pywrap_checkpoint_reader raised unreported exception, mean a compiled module and the installed NumPy disagree on NumPy's C-API. Usually the module was built for NumPy 1.x while NumPy 2 is installed: upgrade it (TensorFlow 2.18 or newer) or pin numpy<2. Less often, NumPy is older than the build.

  • Applies to NumPy 2.5.5 and 1.26.4, TensorFlow 2.21.0 and 2.17.1, Python 3.10 and later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print which NumPy loads and from where, then re-run the failing import and keep only NumPy's own lines. A 'compiled using NumPy 1.x' or '_ARRAY_API not found' line points to cause 1 or 2. A 'compiled against API version' or 'running NumPy has C-API version' line points to cause 3. A NumPy path outside your environment points to cause 4.

Run this first
python -c "import numpy; print(numpy.__version__, numpy.__file__)"
python -c "import tensorflow" 2>&1 | grep -E "NumPy 1.x|_ARRAY_API|API version|multiarray|unreported"

Then find the line you see in this list and open its fix:

  1. 1NumPy 2 is installed under TensorFlow 2.17 or olderpip show tensorflow reports 2.17.x or lower, NumPy reports 2.x, and the failure happens on import tensorflow
  2. 2Another compiled package in the import chain was built for NumPy 1.xReading the traceback from the bottom up, the first file that is not inside numpy belongs to some other package, not TensorFlow
  3. 3The installed NumPy is older than the one the module was built againstThe line above the ImportError says module compiled against API version 0x.. but this version of numpy is 0x.., or that the running NumPy has an older C-API version
  4. 4A second, older NumPy copy is imported firstnumpy.__file__ points outside the virtual environment, for example into a folder listed in PYTHONPATH, while pip in the environment reports a different version

What does the error look like?

  • A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.0 as it may crash.
  • AttributeError: _ARRAY_API not found
  • ImportError: numpy.core.multiarray failed to import
  • SystemError: initialization of _pywrap_checkpoint_reader raised unreported exception
  • RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf

Cause 1 of 4

NumPy 2 is installed under TensorFlow 2.17 or older

You seepip show tensorflow reports 2.17.x or lower, NumPy reports 2.x, and the failure happens on import tensorflow

Check

The 2.17 release notes announce NumPy 2 support for the next version, and 2.18 is the first TensorFlow compiled with NumPy 2.0 by default. Older releases ship modules such as _pywrap_checkpoint_reader built for the 1.x interface. The 2.17.1 wheel even declares numpy<2.0.0, so NumPy 2 lands there only when some later install upgrades it.

Check
pip show tensorflow numpy | grep -E "^(Name|Version)"

Fix

Upgrade TensorFlow, which needs Python 3.10 or newer from 2.21 on. If the project has to stay on 2.17 or older, pin NumPy below 2 in the same command instead.

Fix
python -m pip install -U "tensorflow==2.21.*"
# or, to stay on an old TensorFlow:
python -m pip install "tensorflow==2.17.1" "numpy<2"

Verify

TensorFlow imports and reports its version with no NumPy warning above it.

Verify
python -c "import tensorflow as tf; print(tf.__version__)"

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 4

Another compiled package in the import chain was built for NumPy 1.x

You seeReading the traceback from the bottom up, the first file that is not inside numpy belongs to some other package, not TensorFlow

Check

The NumPy 1.x warning names no package, so the traceback is the guide. NumPy's troubleshooting page says to search it from the back for the first line outside NumPy; that package was compiled against NumPy 1.x and needs a release built for NumPy 2.

Check
python -c "import your_app" 2>&1 | grep 'File "' | grep -v '/numpy/' | tail -3

Fix

Upgrade the package that the traceback names. If it has no NumPy 2 build yet, pin numpy<2 for the whole environment until it does, and tell its maintainers.

Fix
python -m pip install --upgrade <package_name>
# only if no compatible release exists:
python -m pip install "numpy<2"

Verify

The same import runs without the NumPy 1.x warning.

Verify
python -c "import your_app"

Confirmed by numpy.org

Did this fix it?

Cause 3 of 4

The installed NumPy is older than the one the module was built against

You seeThe line above the ImportError says module compiled against API version 0x.. but this version of numpy is 0x.., or that the running NumPy has an older C-API version

Check

NumPy's binary interface works forward, not backward: a module built against an older NumPy runs on newer ones, but one built against a newer NumPy can fail on older ones. An old pin, or version constraints that led pip to an incompatible combination, can leave such a NumPy in place. TensorFlow's own tracker shows this exact case ending in a raised unreported exception SystemError.

Check
python -c "import numpy; print(numpy.__version__)"

Fix

Upgrade NumPy inside the range the failing package declares. TensorFlow 2.21, for example, asks for numpy 1.26.0 or newer.

Fix
python -m pip install --upgrade numpy

Verify

The 'compiled against' line is gone and the import completes.

Verify
python -c "import tensorflow as tf; print(tf.__version__)"

Confirmed by numpy.org

Did this fix it?

Cause 4 of 4

A second, older NumPy copy is imported first

You seenumpy.__file__ points outside the virtual environment, for example into a folder listed in PYTHONPATH, while pip in the environment reports a different version

Check

NumPy's troubleshooting guide asks you to check PYTHONPATH and PATH when Python does not load the NumPy you expect. A stale copy found first on the path wins over the one pip installed, so packages built against the newer one fail.

Check
python -c "import os; print('PYTHONPATH:', os.environ.get('PYTHONPATH'))"
python -m pip show numpy | grep -E "^(Version|Location)"

Fix

Remove the stray entry from PYTHONPATH (or uninstall the stray copy), then reinstall NumPy in the environment and confirm the path changed.

Fix
unset PYTHONPATH
python -m pip install --force-reinstall numpy

Verify

numpy.__file__ now sits inside the environment's site-packages, and the import succeeds.

Verify
python -c "import numpy; print(numpy.__file__)"

Confirmed by numpy.org

Did this fix it?

How do I stop it coming back?

  • Pin numpy with an explicit range in requirements, such as numpy>=1.26,<3, and keep it next to the TensorFlow pin it was tested with.
  • Make CI fail on any pip check output, which flags an installed package whose declared NumPy range is not met.
  • Test a wheel you build against the oldest NumPy you support, as NumPy's packaging guide recommends.
  • Use one virtual environment per project and leave PYTHONPATH unset in its activation.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.