线性模型: numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 得到 80”

Posted

技术标签:

【中文标题】线性模型: numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 得到 80”【英文标题】:linear models: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject" 【发布时间】:2021-06-05 21:23:04 【问题描述】:

当我尝试导入线性模型时收到此错误:“numpy.ndarray 大小已更改,可能表示二进制不兼容。预期 C 标头为 88,从 PyObject 获得 80

我在 Windows 10 上运行 Anaconda,python 3.8.8。它是在新机器上全新安装的 Anaconda Python。

我尝试通过在单独的环境中使用较旧的 NumPy 版本(1.6.1,参见 link)来解决此问题。唉。

这是显示我使用的库版本的输出,注意真正的路径不是c:\users\,而是c:\users\myusername\

Requirement already satisfied: linearmodels in c:\users\anaconda3\lib\site-packages (4.21)
Requirement already satisfied: pandas>=0.24 in c:\users\anaconda3\lib\site-packages (from linearmodels) (1.2.3)
Requirement already satisfied: pyhdfe>=0.1 in  c:\users\anaconda3\lib\site-packages (from linearmodels) (0.1.0)
Requirement already satisfied: scipy>=1.2 in c:\users\anaconda3\lib\site-packages (from linearmodels) (1.6.1)
Requirement already satisfied: statsmodels>=0.11 in c:\users\anaconda3\lib\site-packages (from linearmodels) (0.12.2)
Requirement already satisfied: mypy-extensions>=0.4 in c:\users\anaconda3\lib\site-packages (from linearmodels) (0.4.3)
Requirement already satisfied: property-cached>=1.6.3 in c:\users\anaconda3\lib\site-packages (from linearmodels) (1.6.4)
Requirement already satisfied: numpy>=1.16 in c:\users\anaconda3\lib\site-packages (from linearmodels) (1.19.2)
Requirement already satisfied: patsy in c:\users\anaconda3\lib\site-packages (from linearmodels) (0.5.1)
Requirement already satisfied: Cython>=0.29.21 in c:\users\anaconda3\lib\site-packages (from linearmodels) (0.29.22)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\anaconda3\lib\site-packages (from pandas>=0.24->linearmodels) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in c:\users\anaconda3\lib\site-packages (from pandas>=0.24->linearmodels) (2021.1)
Requirement already satisfied: six>=1.5 in c:\users\anaconda3\lib\site-packages (from python-dateutil>=2.7.3->pandas>=0.24->linearmodels) (1.15.0)

这就是他的错误:

from linearmodels import PanelOLS
Traceback (most recent call last):

  File "<ipython-input-2-6de63ba6aa3f>", line 1, in <module>
    from linearmodels import PanelOLS
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\__init__.py", line 38, in <module>
    from .asset_pricing.model import (
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\asset_pricing\__init__.py", line 1, in <module>
    from .model import LinearFactorModel, LinearFactorModelGMM, TradedFactorModel
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\asset_pricing\model.py", line 13, in <module>
    from linearmodels.asset_pricing.covariance import (
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\asset_pricing\covariance.py", line 9, in <module>
    from linearmodels.iv.covariance import (
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\iv\__init__.py", line 1, in <module>
    from .absorbing import AbsorbingLS, Interaction  # flake8: noqa
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\iv\absorbing.py", line 54, in <module>
    from linearmodels.panel.utility import (
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\panel\__init__.py", line 1, in <module>
    from linearmodels.panel.model import (
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\panel\model.py", line 28, in <module>
    from linearmodels.panel.utility import (
  File "C:\Users\Anaconda3\lib\site-packages\linearmodels\panel\utility.py", line 24, in <module>
    from linearmodels.panel._utility import _drop_singletons
  File "linearmodels\panel\_utility.pyx", line 1, in init linearmodels.panel._utility

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

【问题讨论】:

【参考方案1】:

通过更新到最新的线性模型版本:4.22 解决了这个问题

【讨论】:

linearmodels-4.22 from conda-forge for Linux 在导入linearmodels 时仍然有同样的错误。降级到以前的版本有帮助。 (之前的版本是 4.18。为了降级,我使用了conda install -c conda-forge linearmodels=4.18需要在 Jupyter notebook 上重新启动内核以进行新的降级。)

以上是关于线性模型: numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 得到 80”的主要内容,如果未能解决你的问题,请参考以下文章

QISKIT 错误 - numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 获得 80

HDBSCAN:ValueError:numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88,从 PyObject 得到 80

在 python ValueError 中导入 Gensim:numpy.ndarray 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 88 从 PyObject 得到 80

如何使用cupy循环numpy ndarray?真的会提高执行时间吗?

Numpy.ndarray 对象不可调用错误原因

AttributeError:“numpy.ndarray”对象没有属性“strip”