当我尝试导入线性模型时出现此错误:“ numpy.ndarray 大小已更改,可能表示二进制不兼容。预期 C 标头为 88,从 PyObject 获得 80 ”
我在 Windows 10 上运行 Anaconda,python 3.8.8。它是在新机器上全新安装的 Anaconda Python。
我尝试通过在单独的环境中使用较旧的 NumPy 版本(1.6.1,请参阅此链接)来解决此问题。唉。
这是显示我使用的库版本的输出,并注意真正的路径不是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