Fixing RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility

RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility is a warning which occurs when you have an incompatibility problem between your module and numpy.

Today I try to explain why this error takes place and how to solve it, I will also add other solutions that could solve the error if possible.

Exploring the RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility

This is a warning which occurs when you have an incompatibility problem between your module and numpy.

Do not mix between warnings. Make sure the warning message looks like the warning message bellow after double checking.

                                                                       #
RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility.
                                                                       #

Bellow we will describe how the error can be solved. With multiple possible solutions.

Solution 1 : recompile the modules or downgrade numpy

First, let us understand the problem, the issue occurs when you import a python package which was compiled with another numpy version than the one you have now.

The solution is to just recompile the modules from source without changing the version of numpy you have. You can do that using pip like in the example bellow.

                                                                       #
pip install --no-binary :all: pandas
                                                                       #

After this, the issue should be gone.

If you do not wish to recompile the module or modules, you can just downgrade numpy.

To remove numpy, you can use pip uninstall it.

                                                                       #
pip uninstall numpy
                                                                       #

Then you can use numpy like in the example bellow. Replace v.v.v with the version you want.

                                                                       #
pip install numpy==v.v.v
                                                                       #

The last option is for people who encounter this problem with scipy. The fix is simple you can just use this uninstall command.

                                                                       #
pip uninstall -y scipy scikit-learn
                                                                       #

Finally, install using –no-binary.

                                                                       #
pip install --no-binary scipy scikit-learn
                                                                       #

This solution should be more than enough. If you have been unlucky, you can try to look past the error using the solution bellow.

Solution 2 : ignore the warning numpy.dtype size changed

Since this a warning and not a proper error that breaks your code, you can just choose to ignore it.

You can filter or ignore the warning massages. By adding the following lines to you code..

                                                                       #
# import warnings so you can ignore the warning messages.
import warnings
# ignore warning message numpy.ufunc size changed
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
# ignore warning message numpy.dtype size changed
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
                                                                       #

I hope the fix above fixed your problem, good luck with the scripts to come.

This error could be confusing at first. But once you understand why it is happening, it is easy to solve by only using a more recent method that works and achieves the same function.

Summing-up

This is the end of our article, I hope the solutions I presented worked for you, Learning Python is a fun journey, do not let the errors discourage you.

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