Solve ValueError numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

Solve ValueError numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject is a common error which occurs because of a bug in numpy.

In this post we will try to solve your error and see why it occurs in the first place, we will present multiple solutions so you can find the one that suits your particular situation.

Explaining ValueError numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

The error usually occurs because of a bug in numpy and the fixes are simple.

Before we get into the fix, you might be wondering how we can replicate the error. The error can happen when importing from any script.

Bellow is how the error looks like.

                                                                       #
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
                                                                       #

Bellow are the solutions which worked for me and will help you to successfully solve the annoying error.

Solution 1 : upgrade numpy

First, we should understand that if this is a bug in numpy then upgrading the version of numpy will in all likelihood solve the issue.

You can try solving the issue by uninstalling and then installing numpy.

First, this is how you can uninstall numpy.

                                                                       #
pip uninstall numpy
                                                                       #

After that you can just install it again using pip.

                                                                       #
pip install numpy
                                                                       #

I hope this solution helped you, if it did not try the one bellow.

Solution 2 : keep your version of numpy

It is worth to note that working with numpy versions above numpy 1.20.0 will solve the issue.

If you wish to use a numpy version inferior to 1.20.0 then you can make sure to use these fixes/guidelines.

First, you should install numpy with no-binary.

                                                                       #
pip install <package> install with --no-binary
                                                                       #

And no build isolation.

                                                                       #
pip install <package> install with --no-build-isolation
                                                                       #

If this did not get the error eradicated, try using the solution bellow.

Solution 3 : a fix for TensorFlow

If you are working with TensorFlow and facing the same problem. The issue is almost always with the ‘pycocotools’ package.

You can fix the issue by installing an older version of the pycocotools package.

You can achieve that by running the command bellow.

                                                                       #
pip install pycocotools==1.9.0
                                                                       #

This is just an example, you can choose the version of the pycocotools package you want.

I hope this guide solved your problem, thank you for reading.

Summing-up

This is the end of our guide, I hope you found at least one solution useful, we try to provide solutions for both Linux and windows users, If you did not solve the issue, I hope you find it online, do not give up, errors are normal in Python, Cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/