ImportError: No module named statsmodels.api

13,471

Solution 1

On Ubuntu 12.04, statsmodels is installed through scikits.

Hence:

import scikits.statsmodels.api as sm

Solution 2

from statsmodels import api as sm
Share:
13,471

Related videos on Youtube

F.N.B
Author by

F.N.B

Updated on September 15, 2022

Comments

  • F.N.B
    F.N.B over 1 year

    I'm new in python and have this problem. I have install Pandas, Numpy, Scipy, and I install Stats Models with apt-get install python-statsmodels, but when I try to use:

    import statsmodels.api as sm
    

    But I have this problem:

    ImportError                               Traceback (most recent call last)
    <ipython-input-1-6030a6549dc0> in <module>()
    ----> 1 import statsmodels.api as sm
    
    ImportError: No module named statsmodels.api
    

    Why??

  • F.N.B
    F.N.B almost 11 years
    The error is the same: ImportError: No module named statsmodels
  • RickyA
    RickyA almost 11 years
    Try 'import statsmodels'. If that fails it is not installed correctly. Try to see if it is present in the site-packages dir of your python install. Are you using virtualenv?
  • F.N.B
    F.N.B almost 11 years
    No, I don't use virtualenv. And when I try 'import statsmodels' the error continuous. where I see the site-packages?? Is in /usr/lib/python2.7??
  • RickyA
    RickyA almost 11 years
    from distutils.sysconfig import get_python_lib print(get_python_lib()) seems to be: /usr/lib/python2.7/dist-packages on ubuntu.
  • RickyA
    RickyA almost 11 years
    on Ubuntu it seems to be: /usr/local/lib/python2.7/dist-packages/
  • F.N.B
    F.N.B almost 11 years
    StatsModels don't are in dist-packages, but I install with apt-get, I need install with pip?? or how i do to install in dist-packages?
  • RickyA
    RickyA almost 11 years
    try pip. that normally installs in dist-packages.
  • F.N.B
    F.N.B almost 11 years
    I install with pip, but install in /usr/local/lib/python2.7/dist-packages an not in /usr/lib/python2.7/dist-packages, and the problem continuos, this is the problem?? how I say where do I install it?
  • RickyA
    RickyA almost 11 years
    That is the problem, you cant tell tell it where to install. What you could try is copy all statsmodels stuff from /usr/local/lib/dist-packages to /usr/lib/dist-packages since they are using the same python version.