Python导入statsmodels没有名为'scipy.linlang'的模块

时间:2019-10-02 15:10:56

标签: python statsmodels

我已经安装了scipy和statsmodels,但是在尝试导入statsmodels时遇到错误:

$ pip install scipy
$ pip install statsmodels
$ python
>>> import statsmodels as sm

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pa354/software/miniconda3/lib/python3.7/site-packages/statsmodels/__init__.py", line 10, in <module>
    from statsmodels.tools.sm_exceptions import (ConvergenceWarning, CacheWriteWarning,
  File "/home/pa354/software/miniconda3/lib/python3.7/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
    from .tools import add_constant, categorical
  File "/home/pa354/software/miniconda3/lib/python3.7/site-packages/statsmodels/tools/tools.py", line 8, in <module>
    from scipy.linalg import svdvals
ModuleNotFoundError: No module named 'scipy.linalg'

1 个答案:

答案 0 :(得分:0)

使用以下命令升级到最新版本的scipy:

from django.core.signals import got_request_exception
from django.template import TemplateDoesNotExist
from django.test import signals
from django.test.client import Client as DjangoClient, store_rendered_templates
from django.urls import resolve
from django.utils import six
from django.utils.functional import SimpleLazyObject, curry


class Client(DjangoClient):
    """Test client that does not raise Exceptions if requested."""

    def __init__(self, 
                 enforce_csrf_checks=False, 
                 raise_request_exception=True, **defaults):
        super(Client, self).__init__(enforce_csrf_checks=enforce_csrf_checks, 
                                     **defaults)
        self.raise_request_exception = raise_request_exception

    def request(self, **request):
        """
        The master request method. Composes the environment dictionary
        and passes to the handler, returning the result of the handler.
        Assumes defaults for the query environment, which can be overridden
        using the arguments to the request.
        """
        environ = self._base_environ(**request)

        # Curry a data dictionary into an instance of the template renderer
        # callback function.
        data = {}
        on_template_render = curry(store_rendered_templates, data)
        signal_uid = "template-render-%s" % id(request)
        signals.template_rendered.connect(on_template_render, 
                                          dispatch_uid=signal_uid)
        # Capture exceptions created by the handler.
        exception_uid = "request-exception-%s" % id(request)
        got_request_exception.connect(self.store_exc_info, 
                                      dispatch_uid=exception_uid)
        try:
            try:
                response = self.handler(environ)
            except TemplateDoesNotExist as e:
                # If the view raises an exception, Django will attempt to show
                # the 500.html template. If that template is not available,
                # we should ignore the error in favor of re-raising the
                # underlying exception that caused the 500 error. Any other
                # template found to be missing during view error handling
                # should be reported as-is.
                if e.args != ('500.html',):
                    raise

            # Look for a signalled exception, clear the current context
            # exception data, then re-raise the signalled exception.
            # Also make sure that the signalled exception is cleared from
            # the local cache!
            response.exc_info = self.exc_info  # Patch exception handling
            if self.exc_info:
                exc_info = self.exc_info
                self.exc_info = None
                if self.raise_request_exception:  # Patch exception handling
                    six.reraise(*exc_info)

            # Save the client and request that stimulated the response.
            response.client = self
            response.request = request

            # Add any rendered template detail to the response.
            response.templates = data.get("templates", [])
            response.context = data.get("context")

            response.json = curry(self._parse_json, response)

            # Attach the ResolverMatch instance to the response
            response.resolver_match = SimpleLazyObject(
                lambda: resolve(request['PATH_INFO'])
            )

            # Flatten a single context. Not really necessary anymore thanks to
            # the __getattr__ flattening in ContextList, but has some edge-case
            # backwards-compatibility implications.
            if response.context and len(response.context) == 1:
                response.context = response.context[0]

            # Update persistent cookie data.
            if response.cookies:
                self.cookies.update(response.cookies)

            return response
        finally:
            signals.template_rendered.disconnect(dispatch_uid=signal_uid)
            got_request_exception.disconnect(dispatch_uid=exception_uid)