Python 3.8无法导入statsmodels.api

Python 3.8无法导入statsmodels.api,python,python-3.x,statsmodels,Python,Python 3.x,Statsmodels,在安装statsmodels之前,我安装了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/statsm

在安装statsmodels之前,我安装了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)
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
单独导入statsmodels效果很好。我试图通过完全卸载statsmodels并再次安装,以及通过
pip-install-git安装statsmodels来解决这个问题+https://github.com/statsmodels/statsmodels
,但同样没有运气

所有内容的版本如下:

NumPy:1.18.1
熊猫:0.25.3
SciPy:1.4.1
帕特西:0.5.1
Statsmodels:0.11.1

进一步研究错误消息,我打开statespace文件夹中的文件
\uuuu init.py\uuuu
,发现以下代码:

from statsmodels.tools._testing import PytestTester

test = PytestTester()
运行此代码时,我收到以下错误消息:

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)
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

我不知道这是否意味着什么,因为我只是自己运行代码,但这个问题困扰了我一段时间:请帮助

从错误中的文件中,它需要一个文件名。如果您直接运行该文件,它将无法工作

#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"

从错误中的文件中,它需要一个文件名。如果您直接运行该文件,它将无法工作

#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"

statsmodels/tools/_testing.py
第29行链接:搞乱它并尝试找到它所期望的
statsmodels/tools/_testing.py
第29行链接:搞乱它并尝试找到它所期望的