Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named statsmodels

I downloaded the StatsModels source from this location.

Then untarred to

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

and per this documentation, 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 with a similar problem and checked that setuptools was installed and it was also in

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

I'm kinda of lost on this and would appreciate any help...

I am also running

numpy 1.6

so thats not the problem.

like image 703
Stripers247 Avatar asked Aug 03 '12 03:08

Stripers247


2 Answers

  • 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.

like image 200
jfs Avatar answered Oct 27 '22 21:10

jfs


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

like image 39
muhammed fairoos nm Avatar answered Oct 27 '22 19:10

muhammed fairoos nm