在安装statsmodel之前,我安装了NumPy、SciPy、Pandas和Patsy,但是当我尝试导入statsmodels.api时,我得到了以下错误消息:
ImportError: cannot import name '_initialization' from
'statsmodels.tsa.statespace'
(/Library/Frameworks/Python.framework/Versions/3.8/lib/
python3.8/site-packages/statsmodels/tsa/statespace/__init__.py)单独导入statsmodel可以很好地工作。我试图通过完全卸载statsmodel并重新安装它,以及通过pip install git+https://github.com/statsmodels/statsmodels安装statsmodel来解决这个问题,但同样没有成功。
所有内容的版本如下:
NumPy: 1.18.1
熊猫: 0.25.3
SciPy: 1.4.1
Patsy: 0.5.1
Statsmodel: 0.11.1
进一步调查错误消息时,我打开了statespace文件夹中的文件__init.py__,发现了以下代码:
from statsmodels.tools._testing import PytestTester
test = PytestTester()运行此代码时,我得到以下错误消息:
File "/Library/Frameworks/Python.framework/Versions/
3.8/lib/python3.8/site-packages/statsmodels/tools/_testing.py", line 29, in __init__
raise ValueError('Unable to determine path')
ValueError: Unable to determine path我不知道这是否意味着什么,因为我只是自己运行代码,但这个问题已经困扰了我一段时间:请帮帮我!
发布于 2020-07-12 13:45:40
从错误中的文件https://github.com/statsmodels/statsmodels/blob/f3f89ad777b22e6db565897397ece24d41af5700/statsmodels/tools/_testing.py#L27,它需要一个文件名。如果您直接运行该文件,它将不起作用
#temp.py
def foo():
import sys
f = sys._getframe(1)
print("Name:", f.f_locals.get('__file__', None))
$ python3 ./temp.py
>>> Name: None
# temp2.py
import temp
temp.foo()
$ python3 ./temp2.py
>>> Name: "temp2.py"https://stackoverflow.com/questions/62857223
复制相似问题