ImportError: cannot import name '_representation' from 'statsmodels.tsa.statespace'

697 views
Skip to first unread message

margie....@gwynniebee.com

unread,
Jul 20, 2018, 3:20:51 PM7/20/18
to pystatsmodels
I installed statsmodels using pip3:

bash-3.2$ pip3 install -U statsmodels
Collecting statsmodels
Requirement not upgraded as not directly required: pandas in /usr/local/lib/python3.7/site-packages (from statsmodels) (0.23.3)
Requirement not upgraded as not directly required: patsy in /usr/local/lib/python3.7/site-packages (from statsmodels) (0.5.0)
Requirement not upgraded as not directly required: scipy in /usr/local/lib/python3.7/site-packages (from statsmodels) (1.1.0)
Requirement not upgraded as not directly required: python-dateutil>=2.5.0 in /usr/local/lib/python3.7/site-packages (from pandas->statsmodels) (2.7.3)
Requirement not upgraded as not directly required: pytz>=2011k in /usr/local/lib/python3.7/site-packages (from pandas->statsmodels) (2018.5)
Requirement not upgraded as not directly required: numpy>=1.9.0 in /usr/local/lib/python3.7/site-packages (from pandas->statsmodels) (1.14.5)
Requirement not upgraded as not directly required: six in /usr/local/lib/python3.7/site-packages (from patsy->statsmodels) (1.11.0)
Installing collected packages: statsmodels
Successfully installed statsmodels-0.9.0

However, when I run a program (that someone gave me) that is using it, I get this:

Traceback (most recent call last):
  File "bin/rahul.py", line 5, in <module>
    import statsmodels.api as sm
  File "/usr/local/lib/python3.7/site-packages/statsmodels/api.py", line 7, in <module>
    from .regression.recursive_ls import RecursiveLS
  File "/usr/local/lib/python3.7/site-packages/statsmodels/regression/recursive_ls.py", line 16, in <module>
    from statsmodels.tsa.statespace.mlemodel import (
  File "/usr/local/lib/python3.7/site-packages/statsmodels/tsa/statespace/mlemodel.py", line 18, in <module>
    from .simulation_smoother import SimulationSmoother
  File "/usr/local/lib/python3.7/site-packages/statsmodels/tsa/statespace/simulation_smoother.py", line 10, in <module>
    from .kalman_smoother import KalmanSmoother
  File "/usr/local/lib/python3.7/site-packages/statsmodels/tsa/statespace/kalman_smoother.py", line 11, in <module>
    from statsmodels.tsa.statespace.representation import OptionWrapper
  File "/usr/local/lib/python3.7/site-packages/statsmodels/tsa/statespace/representation.py", line 10, in <module>
    from .tools import (
  File "/usr/local/lib/python3.7/site-packages/statsmodels/tsa/statespace/tools.py", line 207, in <module>
    set_mode(compatibility=None)
  File "/usr/local/lib/python3.7/site-packages/statsmodels/tsa/statespace/tools.py", line 59, in set_mode
    from . import (_representation, _kalman_filter, _kalman_smoother,
ImportError: cannot import name '_representation' from 'statsmodels.tsa.statespace' (/usr/local/lib/python3.7/site-packages/statsmodels/tsa/statespace/__init__.py)
bash-3.2$ 

Anyone know what I can do to fix this?

josef...@gmail.com

unread,
Jul 20, 2018, 3:31:05 PM7/20/18
to pystatsmodels
Failing to load/import a cython extension is most of the time because
of some binary incompatibilities, in the case of statsmodels with
either numpy or scipy.

I don't know what the versions are on Linux, so I don't know what
specific incompatibility might cause this.
However, this is the first case that I see using python 3.7. So most
likely the source needs to be cythonized with a Cython version that is
compatible with python 3.7.

When I run into this on Windows I usually just recompile statsmodels
in the python version that has the appropriate numpy and scipy that I
want to use with statsmodels.
Building/compiling statsmodels from the source distribution requires
only a C compiler. Building from the github source requires also
Cython. In this case forcing cythonizing with a newer version might be
necessary.

Josef
Reply all
Reply to author
Forward
0 new messages