[翻译]  RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility

[CHINESE]  RuntimeWarning:numpy.dtype大小已更改,可能表示二进制不兼容

I have this error for trying to load a saved SVM model. I have tried uninstalling sklearn, NumPy and SciPy, reinstalling the latest versions all-together again (using pip). I am still getting this error. Why?


In [1]: import sklearn; print sklearn.__version__
In [3]: import numpy; print numpy.__version__
In [5]: import scipy; print scipy.__version__
In [7]: import pandas; print pandas.__version__

In [10]: clf = joblib.load('model/trained_model.pkl')
RuntimeWarning                            Traceback (most recent call last)
<ipython-input-10-5e5db1331757> in <module>()
----> 1 clf = joblib.load('sentiment_classification/model/trained_model.pkl')

/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/numpy_pickle.pyc in load(filename, mmap_mode)
    573                     return load_compatibility(fobj)
--> 575                 obj = _unpickle(fobj, filename, mmap_mode)
    577     return obj

/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/numpy_pickle.pyc in _unpickle(fobj, filename, mmap_mode)
    505     obj = None
    506     try:
--> 507         obj = unpickler.load()
    508         if unpickler.compat_mode:
    509             warnings.warn("The file '%s' has been generated with a "

/usr/lib/python2.7/pickle.pyc in load(self)
    862             while 1:
    863                 key = read(1)
--> 864                 dispatch[key](self)
    865         except _Stop, stopinst:
    866             return stopinst.value

/usr/lib/python2.7/pickle.pyc in load_global(self)
   1094         module = self.readline()[:-1]
   1095         name = self.readline()[:-1]
-> 1096         klass = self.find_class(module, name)
   1097         self.append(klass)
   1098     dispatch[GLOBAL] = load_global

/usr/lib/python2.7/pickle.pyc in find_class(self, module, name)
   1128     def find_class(self, module, name):
   1129         # Subclasses may override this
-> 1130         __import__(module)
   1131         mod = sys.modules[module]
   1132         klass = getattr(mod, name)

/usr/local/lib/python2.7/dist-packages/sklearn/svm/__init__.py in <module>()
     11 # License: BSD 3 clause (C) INRIA 2010
---> 13 from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
     14         LinearSVR
     15 from .bounds import l1_min_c

/usr/local/lib/python2.7/dist-packages/sklearn/svm/classes.py in <module>()
      2 import numpy as np
----> 4 from .base import _fit_liblinear, BaseSVC, BaseLibSVM
      5 from ..base import BaseEstimator, RegressorMixin
      6 from ..linear_model.base import LinearClassifierMixin, SparseCoefMixin, \

/usr/local/lib/python2.7/dist-packages/sklearn/svm/base.py in <module>()
      6 from abc import ABCMeta, abstractmethod
----> 8 from . import libsvm, liblinear
      9 from . import libsvm_sparse
     10 from ..base import BaseEstimator, ClassifierMixin

__init__.pxd in init sklearn.svm.libsvm (sklearn/svm/libsvm.c:10207)()

RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 80

UPDATE: OK, by following here, and


pip uninstall -y scipy scikit-learn
pip install --no-binary scipy scikit-learn

The error has now gone, though I still have no idea why it occurred in the first place...


6 个解决方案



According to MAINT: silence Cython warnings about changes dtype/ufunc size. - numpy/numpy:

根据MAINT:沉默Cython关于更改dtype / ufunc大小的警告。 - numpy / numpy:

These warnings are visible whenever you import scipy (or another package) that was compiled against an older numpy than is installed.


and the checks are inserted by Cython (hence are present in any module compiled with it).


Long story short, these warnings should be benign in the particular case of numpy, and these messages are filtered out since numpy 1.8 (the branch this commit went onto). While scikit-learn 0.18.1 is compiled against numpy 1.6.1.

简而言之,这些警告在numpy的特定情况下应该是良性的,并且这些消息从numpy 1.8(此提交的分支)开始被过滤掉。虽然scikit-learn 0.18.1是针对numpy 1.6.1编译的。

To filter these warnings yourself, you can do the same as the patch does:


import warnings
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")

Of course, you can just recompile all affected modules from source against your local numpy with pip install --no-binary :all:¹ instead if you have the balls tools for that.

当然,您可以使用pip install --no-binary:all:¹来重新编译来自源的所有受影响的模块,而不是使用其中的球工具。

Longer story: the patch's proponent claims there should be no risk specifically with numpy, and 3rd-party packages are intentionally built against older versions:


[Rebuilding everything against current numpy is] not a feasible solution, and certainly shouldn't be necessary. Scipy (as many other packages) is compatible with a number of versions of numpy. So when we distribute scipy binaries, we build them against the lowest supported numpy version (1.5.1 as of now) and they work with 1.6.x, 1.7.x and numpy master as well.

[重建当前numpy的一切]不是一个可行的解决方案,当然不应该是必要的。 Scipy(与许多其他软件包一样)与numpy的许多版本兼容。因此,当我们分发scipy二进制文件时,我们会根据最低支持的numpy版本(目前为1.5.1)构建它们,并且它们也适用于1.6.x,1.7.x和numpy master。

The real correct would be for Cython only to issue warnings when the size of dtypes/ufuncs has changes in a way that breaks the ABI, and be silent otherwise.

真正正确的是,当dtypes / ufuncs的大小以打破ABI的方式发生变化时,Cython只会发出警告,否则就会保持沉默。

As a result, Cython's devs agreed to trust the numpy team with maintaining binary compatibility by hand, so we can probably expect that using versions with breaking ABI changes would yield a specially-crafted exception or some other explicit show-stopper.


¹The previously available --no-use-wheel option has been removed since pip 10.0.0.

¹自从pip 10.0.0起,以前可用的--no-use-wheel选项已被删除。



I've tried the above-mentioned ways, but nothing worked. But the issue was gone after I installed the libraries through apt install,

我尝试过上述方法,但没有任何效果。但是我通过apt install安装库后问题就消失了,

pip uninstall -y numpy scipy pandas scikit-learn
sudo apt update
sudo apt install python3-numpy python3-scipy python3-pandas python3-sklearn 

Hope that helps.




if you are in an anaconda environment use:


conda update --all



This error occurs because the installed packages were build agains different version of numpy.
We need to rebuild scipy and scikit-learn against the local numpy.

发生此错误是因为已安装的软件包再次构建不同版本的numpy。我们需要重建scipy和scikit - 学习当地的numpy。

For new pip (in my case pip 18.0) this worked:

对于新的pip(在我的情况下是pip 18.0),这有效:

pip uninstall -y scipy scikit-learn
pip install --no-binary scipy,scikit-learn -I scipy scikit-learn

--no-binary takes a list of names of packages that you want to ignore binaries for. In this case we passed --no-binary scipy,scikit-learn which will ignore binaries for packages scipy,scikit-learn. Didn't help me

--no-binary获取要忽略二进制文件的包的名称列表。在这种情况下,我们通过了--no-binary scipy,scikit-learn,它将忽略包scipy,scikit-learn的二进制文件。没帮我



My enviroment is Python 2.7.15

我的环境是Python 2.7.15

I try


pip uninstall
pip install --no-use-wheel

but it does not work. It shows the error:


no such option: --no-use-wheel

没有这样的选择: - no-use-wheel

Then I try:


pip uninstall
pip install --user --install-option="--prefix=" -U scikit-learn

And it works: the useless warnings do not show.




When import scipy, error info shows: RuntimeWarning: builtin.type size changed, may indicate binary incompatibility. Expected zd, got zd

导入scipy时,错误信息显示:RuntimeWarning:builtin.type size更改,可能表示二进制不兼容。期待zd,得到了zd

I solved this problem by updating python version from 2.7.2 to 2.7.13




© 2014-2018 ITdaan.com 粤ICP备14056181号