ValueError: numpy.dtype 有错误的大小,尝试重新编译 [英] ValueError: numpy.dtype has the wrong size, try recompiling

查看:46
本文介绍了ValueError: numpy.dtype 有错误的大小,尝试重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的 python 2.7 上安装了 pandas 和 statsmodels 包当我尝试将熊猫导入为 pd"时,出现此错误消息.任何人都可以帮忙吗?谢谢!!!

I just installed pandas and statsmodels package on my python 2.7 When I tried "import pandas as pd", this error message comes out. Can anyone help? Thanks!!!

numpy.dtype has the wrong size, try recompiling
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:analyticsextpython27libsite-packagesstatsmodels-0.5.0-py2.7-win32.eggstatsmodelsformula\__init__.py",
line 4, in <module>
    from formulatools import handle_formula_data
  File "C:analyticsextpython27libsite-packagesstatsmodels-0.5.0-py2.7-win32.eggstatsmodelsformulaformulatools.p
y", line 1, in <module>
    import statsmodels.tools.data as data_util
  File "C:analyticsextpython27libsite-packagesstatsmodels-0.5.0-py2.7-win32.eggstatsmodels	ools\__init__.py", li
ne 1, in <module>
    from tools import add_constant, categorical
  File "C:analyticsextpython27libsite-packagesstatsmodels-0.5.0-py2.7-win32.eggstatsmodels	ools	ools.py", line
14, in <module>
    from pandas import DataFrame
  File "C:analyticsextpython27libsite-packagespandas\__init__.py", line 6, in <module>
    from . import hashtable, tslib, lib
  File "numpy.pxd", line 157, in init pandas.tslib (pandas	slib.c:49133)
ValueError: numpy.dtype has the wrong size, try recompiling

推荐答案

(对我的评论进行一点扩展)

(to expand a bit on my comment)

Numpy 开发人员通常遵循保持向后兼容的二进制接口 (ABI) 的策略.但是,ABI 不向前兼容.

Numpy developers follow in general a policy of keeping a backward compatible binary interface (ABI). However, the ABI is not forward compatible.

这意味着:

在编译扩展中使用 numpy 的包是针对特定版本的 numpy 编译的.numpy 的未来版本将与包的编译扩展兼容(例外情况见下文).这些其他包的分发者不需要针对较新版本的 numpy 重新编译他们的包,并且当用户更新到较新版本的 numpy 时,用户也不需要更新这些其他包.

A package, that uses numpy in a compiled extension, is compiled against a specific version of numpy. Future version of numpy will be compatible with the compiled extension of the package (for exception see below). Distributers of those other packages do not need to recompile their package against a newer versions of numpy and users do not need to update these other packages, when users update to a newer version of numpy.

然而,这并没有往另一个方向发展.如果一个包是针对特定的 numpy 版本(比如 1.7)编译的,那么就不能保证该包的二进制文件可以与较旧的 numpy 版本(比如 1.6)一起使用,而且通常或大部分时间它们不会.

However, this does not go in the other direction. If a package is compiled against a specific numpy version, say 1.7, then there is no guarantee that the binaries of that package will work with older numpy versions, say 1.6, and very often or most of the time they will not.

pandas 和 statsmodels 等软件包的二进制分发包是针对最新版本的 numpy 编译的,当安装了旧版本的 numpy 时将无法使用.一些包,例如 matplotlib,如果我没记错的话,会根据它们支持的最旧的 numpy 版本编译它们的扩展.在这种情况下,使用相同旧版本或任何更新版本的 numpy 的用户可以使用这些二进制文件.

The binary distribution of packages like pandas and statsmodels, that are compiled against a recent version of numpy, will not work when an older version of numpy is installed. Some packages, for example matplotlib, if I remember correctly, compile their extensions against the oldest numpy version that they support. In this case, users with the same old or any more recent version of numpy can use those binaries.

问题中的错误消息是二进制不兼容的典型结果.

The error message in the question is a typical result of binary incompatibilities.

解决方案是获得二进制兼容版本,方法是将 numpy 至少更新为编译 pandas 或 statsmodels 的版本,或者针对已安装的旧版本 numpy 重新编译 pandas 和 statsmodels.

The solution is to get a binary compatible version, either by updating numpy to at least the version against which pandas or statsmodels were compiled, or to recompile pandas and statsmodels against the older version of numpy that is already installed.

打破 ABI 向后兼容性:

Breaking the ABI backward compatibility:

有时 numpy 中的改进或重构会破坏 ABI 向后兼容性.这(无意)发生在 numpy 1.4.0 中.因此,将 numpy 更新到 1.4.0 的用户与所有其他编译包的二进制不兼容,这些包是针对以前版本的 numpy 编译的.这要求所有使用 numpy 的具有二进制扩展名的包都必须重新编译才能与 ABI 不兼容的版本一起使用.

Sometimes improvements or refactorings in numpy break ABI backward compatibility. This happened (unintentionally) with numpy 1.4.0. As a consequence, users that updated numpy to 1.4.0, had binary incompatibilities with all other compiled packages, that were compiled against a previous version of numpy. This requires that all packages with binary extensions that use numpy have to be recompiled to work with the ABI incompatible version.

这篇关于ValueError: numpy.dtype 有错误的大小,尝试重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆