ImportError: No module named statsmodels

霸气de小男生 提交于 2020-05-25 05:45:28

问题


Hi I downloaded the StatsModels source from http://pypi.python.org/pypi/statsmodels#downloads I then untarred to

/usr/local/lib/python2.7/dist-packages

and per the documentation at http://statsmodels.sourceforge.net/devel/install.html did this

sudo python setup.py install

It installed, but when I try to import

import statsmodels.api as sm

I get the following error

Traceback (most recent call last):
  File "/home/Astrophysics/Histogram_Fast.py", line 6, in <module>
import statsmodels.api as sm
ImportError: No module named statsmodels.api

I read a few post that have had a similar problem and checked that setuptools was installed and it was also in

 /usr/local/lib/python2.7/dist-packages

I'm kinda at a loss on this and would appriceate any help

I am also running

numpy 1.6

so thats not the problem


回答1:


  • you shouldn't untar it to /usr/local/lib/python2.7/dist-packages (you could use any temporary directory)
  • you might have used by mistake a different python executable e.g., /usr/bin/python instead of the one corresponding to /usr/local/lib/python2.7

You should use pip corresponding to a desired python version (use python -V to check the version) to install it:

$ python -m pip install statsmodels 

It would allow you to upgrade/uninstall it easily.

Don't install as a root to avoid the risk of messing with system python installation by accident. You could use --user option or virtualenv instead.




回答2:


You have to upgrade the package pytest. I had the same issue importing in a Jupyter notebook on Ubuntu python 2.7

import statsmodels.api as sm

I also had to restart the Jupyter notebook.

sudo python -m pip install pytest --upgrade




回答3:


Try installing using the path directly,

For example, pip install --user "downloaded_package_path"

Then try importing the statsmodels, import statsmodels.api as sm




回答4:


As per documentation, you can install using the following commands

pip install --upgrade --no-deps statsmodels

using conda

conda install statsmodels

Then restart your jupyter notebook

if you facing an error like no module pasty stop your jupyter notebook and try the below command on terminal

pip install patsy

Don't forget to restart your jupyter notebook Let's hope




回答5:


Install patsy:

pip install --upgrade patsy

Install statsmodels

pip install statsmodels

docs here



来源:https://stackoverflow.com/questions/11788900/importerror-no-module-named-statsmodels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!