简体   繁体   English

无法导入统计模型

[英]Unable to import statsmodels

I am new to python and I am trying to learn how to use it for statistics.我是 python 的新手,我正在尝试学习如何使用它进行统计。 I have been trying to use the我一直在尝试使用

from statsmodels.stats.weightstats import ztest

But I get an error when I try to use this command.但是当我尝试使用此命令时出现错误。 Here is what it displayed:这是它显示的内容:

Python 2.7.17 (default, Nov  7 2019, 10:07:09) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from statsmodels.stats.weightstats import ztest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/stats/__init__.py", line 1, in <module>
    from statsmodels.tools._testing import PytestTester
  File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
    from .tools import add_constant, categorical
  File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/tools.py", line 8, in <module>
    from statsmodels.compat.python import lzip, lmap
  File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/__init__.py", line 1, in <module>
    from statsmodels.tools._testing import PytestTester
  File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/_testing.py", line 11, in <module>
    from statsmodels.compat.pandas import assert_equal
  File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/pandas.py", line 4, in <module>
    import numpy as np
  File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/numpy.py", line 46, in <module>
    NP_LT_114 = LooseVersion(np.__version__) < LooseVersion('1.14')
AttributeError: 'module' object has no attribute '__version__'
>>> 

Any help that I can get would be appreciated.我能得到的任何帮助将不胜感激。 I am using python 2.7.17我正在使用 python 2.7.17

I'm also working on python 2.7 facing exactly the same problem.我也在研究 python 2.7 面临完全相同的问题。 Here's how I solved it:这是我解决它的方法:

First thing first, it says in error message首先,它在错误消息中说

NP_LT_114 = LooseVersion(np. version ) < LooseVersion('1.14') Thus make sure you have numpy version > 1.14 NP_LT_114 = LooseVersion(np. version ) < LooseVersion('1.14') 因此确保你有 numpy 版本 > 1.14

Secondly, I downgraded statsmodels from 0.11.0 to 0.10.0.其次,我将 statsmodels 从 0.11.0 降级到 0.10.0。

Hope it works for you too.希望它也适用于你。

(numpy==1.16.5, statsmodels==0.10.0, python=2.7) (numpy==1.16.5,统计模型==0.10.0,python=2.7)

Just had this issue after conda chose to update numpy from 1.13.3 to 1.14.3.在 conda 选择将 numpy 从 1.13.3 更新到 1.14.3 后才遇到这个问题。 Reverting numpy via procedure in http://blog.rtwilson.com/conda-revisions-letting-you-rollback-to-a-previous-version-of-your-environment/ sufficed to recover functionality, followed by pinning the version in the environment.通过http://blog.rtwilson.com/conda-revisions-letting-you-rollback-to-a-previous-version-of-your-environment/ 中的过程恢复 numpy 足以恢复功能,然后将版本固定在环境。

also wondering what does shows:还想知道什么显示:

import numpy; print(numpy.__file__)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM