Error when import statsmodels 0.80

489 views
Skip to first unread message

Jun C.

unread,
Aug 9, 2017, 11:56:00 AM8/9/17
to cython-users

I am setting up Rodeo with a few imports for the first time as newbie to python:


import sys 
import pandas as pd
import pylab as pl
import numpy as np
import statsmodels.api as sm



But import statsmodels keeps giving errors. Here is the latest one:


>>> import statsmodels.api as sm
ImportError: cannot import name '_representation'
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-6030a6549dc0> in <module>()
----> 1 import statsmodels.api as sm
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\api.py in <module>()
      5 from . import regression
      6 from .regression.linear_model import OLS, GLS, WLS, GLSAR
----> 7 from .regression.recursive_ls import RecursiveLS
      8 from .regression.quantile_regression import QuantReg
      9 from .regression.mixed_linear_model import MixedLM
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\regression\recursive_ls.py in <module>()
     14 from statsmodels.regression.linear_model import OLS
     15 from statsmodels.tools.data import _is_using_pandas
---> 16 from statsmodels.tsa.statespace.mlemodel import (
     17     MLEModel, MLEResults, MLEResultsWrapper)
     18 from statsmodels.tools.tools import Bunch
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\mlemodel.py in <module>()
     13 from scipy.stats import norm
     14 
---> 15 from .simulation_smoother import SimulationSmoother
     16 from .kalman_smoother import SmootherResults
     17 from .kalman_filter import (INVERT_UNIVARIATE, SOLVE_LU)
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\simulation_smoother.py in <module>()
      8 
      9 import numpy as np
---> 10 from .kalman_smoother import KalmanSmoother
     11 from . import tools
     12 
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\kalman_smoother.py in <module>()
      9 import numpy as np
     10 
---> 11 from statsmodels.tsa.statespace.representation import OptionWrapper
     12 from statsmodels.tsa.statespace.kalman_filter import (KalmanFilter,
     13                                                       FilterResults)
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\representation.py in <module>()
      8 
      9 import numpy as np
---> 10 from .tools import (
     11     find_best_blas_type, validate_matrix_shape, validate_vector_shape
     12 )
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\tools.py in <module>()
    205             'z': _statespace.zcopy_index_vector
    206         })
--> 207 set_mode(compatibility=None)
    208 
    209 
c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\tools.py in set_mode(compatibility)
     57     if not compatibility:
     58         from scipy.linalg import cython_blas
---> 59         from . import (_representation, _kalman_filter, _kalman_smoother,
     60                        _simulation_smoother, _tools)
     61         compatibility_mode = False
ImportError: cannot import name '_representation'

Tried to install Cython 0.26, 0.25.2, 0.25.1 and the importing error is the same with statsmodels. The problem seems to be with Cython. Any idea to fix the problem? Thanks.

Stefan Behnel

unread,
Aug 9, 2017, 12:12:31 PM8/9/17
to cython...@googlegroups.com
Jun C. schrieb am 09.08.2017 um 07:13:
> I am setting up Rodeo with a few imports for the first time as newbie to
> python:
>
> import sys
> import pandas as pd
> import pylab as pl
> import numpy as np
> import statsmodels.api as sm
>
> But import statsmodels keeps giving errors. Here is the latest one:
>
> >>> import statsmodels.api as smImportError: cannot import name '_representation'---------------------------------------------------------------------------ImportError Traceback (most recent call last)<ipython-input-2-6030a6549dc0> in <module>()----> 1 import statsmodels.api as sm
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\api.py in <module>()
> 5 from . import regression
> 6 from .regression.linear_model import OLS, GLS, WLS, GLSAR----> 7 from .regression.recursive_ls import RecursiveLS
> 8 from .regression.quantile_regression import QuantReg
> 9 from .regression.mixed_linear_model import MixedLM
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\regression\recursive_ls.py in <module>()
> 14 from statsmodels.regression.linear_model import OLS
> 15 from statsmodels.tools.data import _is_using_pandas---> 16 from statsmodels.tsa.statespace.mlemodel import (
> 17 MLEModel, MLEResults, MLEResultsWrapper)
> 18 from statsmodels.tools.tools import Bunch
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\mlemodel.py in <module>()
> 13 from scipy.stats import norm
> 14 ---> 15 from .simulation_smoother import SimulationSmoother
> 16 from .kalman_smoother import SmootherResults
> 17 from .kalman_filter import (INVERT_UNIVARIATE, SOLVE_LU)
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\simulation_smoother.py in <module>()
> 8
> 9 import numpy as np---> 10 from .kalman_smoother import KalmanSmoother
> 11 from . import tools
> 12
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\kalman_smoother.py in <module>()
> 9 import numpy as np
> 10 ---> 11 from statsmodels.tsa.statespace.representation import OptionWrapper
> 12 from statsmodels.tsa.statespace.kalman_filter import (KalmanFilter,
> 13 FilterResults)
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\representation.py in <module>()
> 8
> 9 import numpy as np---> 10 from .tools import (
> 11 find_best_blas_type, validate_matrix_shape, validate_vector_shape
> 12 )
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\tools.py in <module>()
> 205 'z': _statespace.zcopy_index_vector
> 206 })--> 207 set_mode(compatibility=None)
> 208
> 209
> c:\python36\lib\site-packages\statsmodels-0.8.0-py3.6-win-amd64.egg\statsmodels\tsa\statespace\tools.py in set_mode(compatibility)
> 57 if not compatibility:
> 58 from scipy.linalg import cython_blas---> 59 from . import (_representation, _kalman_filter, _kalman_smoother,
> 60 _simulation_smoother, _tools)
> 61 compatibility_mode = FalseImportError: cannot import name '_representation'
>
> Tried to install Cython 0.26, 0.25.2, 0.25.1 and the importing error is the same with statsmodels. The problem seems to be with Cython. Any idea to fix the problem? Thanks.


"statsmodels" might have a circular import that prevents proper setup of
the module namespaces in the right order. Assuming you can edit the source
code:

- remove the circular imports

- try recompiling with latest Cython master, which implements PEP 489

- try replacing "from . import NAMES" imports with simple module imports
that do not require specific names to be in the module namespace already,
so that circular dependencies can be looked up later, after finishing the
module initialisation

Note that people commonly run into similar problems also with normal Python
modules. This isn't really a problem specific to Cython.

Stefan

Jun C.

unread,
Aug 9, 2017, 4:58:12 PM8/9/17
to cython-users
Stefan,

Thank you for the reply. I am new to the python (from ruby/ROR) and prefer not to touch the source code (or don't know how) for now. I thought this should be very basic issues and did not realize it takes a lot of effort to import a package right. Is there more reading available for me to understand better about the issue and follow a step by step guide to fix?

Best Regards
-JunC

Stefan Behnel

unread,
Aug 9, 2017, 5:14:37 PM8/9/17
to cython...@googlegroups.com
Jun C. schrieb am 09.08.2017 um 20:26:
> Thank you for the reply. I am new to the python (from ruby/ROR) and prefer
> not to touch the source code (or don't know how) for now. I thought this
> should be very basic issues and did not realize it takes a lot of effort to
> import a package right.

Sorry, no, that should actually be simple. The problem is that you've run
into a bug, and I was really just guessing what the most likely reason
could be, and proposing ways how to fix it on the side of the statsmodels
project.

Could you report this to their bug tracker? I think it's this one:

https://github.com/statsmodels/statsmodels/issues

They seem to be using travis and apparently also appveyor to test their
package in various Python versions including Py3.6, so I can't say why this
problem shows on your side but not for them. In any case, I think they will
have to do something on their side in the end in order to get this resolved.

Stefan
Reply all
Reply to author
Forward
0 new messages