How to fix numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

Problem

While running your Python application, you see the following exception:

Traceback (most recent call last):
  File "/app/run.py", line 2, in <module>
    from S3IO import *
  File "/app/data.py", line 2, in <module>
    import pandas as pd
  File "/usr/local/lib/python3.11/site-packages/pandas/__init__.py", line 22, in <module>
    from pandas.compat import is_numpy_dev as _is_numpy_dev  # pyright: ignore # noqa:F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pandas/compat/__init__.py", line 18, in <module>
    from pandas.compat.numpy import (
  File "/usr/local/lib/python3.11/site-packages/pandas/compat/numpy/__init__.py", line 4, in <module>
    from pandas.util.version import Version
  File "/usr/local/lib/python3.11/site-packages/pandas/util/__init__.py", line 2, in <module>
    from pandas.util._decorators import (  # noqa:F401
  File "/usr/local/lib/python3.11/site-packages/pandas/util/_decorators.py", line 14, in <module>
    from pandas._libs.properties import cache_readonly
  File "/usr/local/lib/python3.11/site-packages/pandas/_libs/__init__.py", line 13, in <module>
    from pandas._libs.interval import Interval
  File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

Solution

You are using a version of NumPy which is not compatible with the version of pandas you are using. To fix this, you need to downgrade numpy to a version that is compatible with your pandas version.

pip install numpy==1.26.4

will most often fix the issue. If that doesn’t work, try to use an older version of pandas, or a newer version of Python together with up-to-date versions of NumPy and pandas.