import statsmodels.api as sm 时 ImportError: DLL load failed while importing _arpack: 找不到指定的程序。

2022-05-09 09:12:35 浏览数 (3)

import statsmodels.api as sm 时 报错如下:

解决过程曲折,大致就是 scipy 版本与 statsmodels 的有些方法 不兼容,scipy==1.6.0后,问题解决了:

代码语言:javascript复制
(base) C:UsersAdministrator>pip uninstall statsmodels
Found existing installation: statsmodels 0.11.1
Uninstalling statsmodels-0.11.1:
  Would remove:
    d:pythonanaconda3libsite-packagesstatsmodels-0.11.1.dist-info*
    d:pythonanaconda3libsite-packagesstatsmodels*
Proceed (y/n)? y
  Successfully uninstalled statsmodels-0.11.1

(base) C:UsersAdministrator>pip install statsmodels==0.12.0 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple
Collecting statsmodels==0.12.0
  Downloading http://pypi.doubanio.com/packages/37/22/959fdc710b6b384ad21a876130000557163978880dc50e16ba5d4ce35c18/statsmodels-0.12.0-cp38-none-win_amd64.whl (9.2 MB)
     |████████████████████████████████| 9.2 MB 6.4 MB/s
Requirement already satisfied: scipy>=1.1 in d:pythonanaconda3libsite-packages (from statsmodels==0.12.0) (1.5.0)
Requirement already satisfied: numpy>=1.15 in d:pythonanaconda3libsite-packages (from statsmodels==0.12.0) (1.20.3)
Requirement already satisfied: pandas>=0.21 in d:pythonanaconda3libsite-packages (from statsmodels==0.12.0) (1.3.4)
Requirement already satisfied: patsy>=0.5 in d:pythonanaconda3libsite-packages (from statsmodels==0.12.0) (0.5.1)
Requirement already satisfied: python-dateutil>=2.7.3 in d:pythonanaconda3libsite-packages (from pandas>=0.21->statsmodels==0.12.0) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in d:pythonanaconda3libsite-packages (from pandas>=0.21->statsmodels==0.12.0) (2020.1)
Requirement already satisfied: six in d:pythonanaconda3libsite-packages (from patsy>=0.5->statsmodels==0.12.0) (1.15.0)
Installing collected packages: statsmodels
Successfully installed statsmodels-0.12.0

(base) C:UsersAdministrator>pip show scipy
Name: scipy
Version: 1.5.0
Summary: SciPy: Scientific Library for Python
Home-page: https://www.scipy.org
Author: None
Author-email: None
License: BSD
Location: d:pythonanaconda3libsite-packages
Requires: numpy
Required-by: -tatsmodels, xgboost, wxgl, sweetviz, stldecompose, statsmodels, sesd, seaborn, scikit-learn, scikit-image, resampy, pyod, mplsoccer, missingno, lightgbm, librosa, imgaug, imbalanced-learn, gensim, filterpy, factor-analyzer, combo, category-encoders, catboost, bayesian-optimization, albumentations

(base) C:UsersAdministrator>pip uninstall scipy
Found existing installation: scipy 1.5.0
Uninstalling scipy-1.5.0:
  Would remove:
    d:pythonanaconda3libsite-packagesscipy-1.5.0.dist-info*
    d:pythonanaconda3libsite-packagesscipy*
Proceed (y/n)? y
  Successfully uninstalled scipy-1.5.0
ERROR: Exception:
Traceback (most recent call last):
  File "D:pythonAnaconda3libsite-packagespip_internalclibase_command.py", line 188, in _main
    status = self.run(options, args)
  File "D:pythonAnaconda3libsite-packagespip_internalcommandsuninstall.py", line 89, in run
    uninstall_pathset.commit()
  File "D:pythonAnaconda3libsite-packagespip_internalreqreq_uninstall.py", line 450, in commit
    self._moved_paths.commit()
  File "D:pythonAnaconda3libsite-packagespip_internalreqreq_uninstall.py", line 290, in commit
    save_dir.cleanup()
  File "D:pythonAnaconda3libsite-packagespip_internalutilstemp_dir.py", line 196, in cleanup
    rmtree(self._path)
  File "D:pythonAnaconda3libsite-packagespip_vendorretrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "D:pythonAnaconda3libsite-packagespip_vendorretrying.py", line 212, in call
    raise attempt.get()
  File "D:pythonAnaconda3libsite-packagespip_vendorretrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "D:pythonAnaconda3libsite-packagespip_vendorsix.py", line 703, in reraise
    raise value
  File "D:pythonAnaconda3libsite-packagespip_vendorretrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "D:pythonAnaconda3libsite-packagespip_internalutilsmisc.py", line 135, in rmtree
    shutil.rmtree(dir, ignore_errors=ignore_errors,
  File "D:pythonAnaconda3libshutil.py", line 737, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "D:pythonAnaconda3libshutil.py", line 610, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "D:pythonAnaconda3libshutil.py", line 610, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "D:pythonAnaconda3libshutil.py", line 615, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "D:pythonAnaconda3libshutil.py", line 613, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] 拒绝访问。: 'D:\python\Anaconda3\Lib\site-packages\~cipy\fft\_pocketfft\pypocketfft.cp38-win_amd64.pyd'

(base) C:UsersAdministrator>pip install scipy --user -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple
Collecting scipy
  Downloading http://pypi.doubanio.com/packages/56/a3/591dbf477c35f173279afa7b9ba8e13d9c7c3d001e09aebbf6100aae33a8/scipy-1.8.0-cp38-cp38-win_amd64.whl (36.9 MB)
     |████████████████████████████████| 36.9 MB 3.3 MB/s
Requirement already satisfied: numpy<1.25.0,>=1.17.3 in d:pythonanaconda3libsite-packages (from scipy) (1.20.3)
Installing collected packages: scipy
Successfully installed scipy-1.8.0

(base) C:UsersAdministrator>python
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import statsmodels.api as sm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:pythonAnaconda3libsite-packagesstatsmodelsapi.py", line 27, in <module>
    from .tsa import api as tsa
  File "D:pythonAnaconda3libsite-packagesstatsmodelstsaapi.py", line 31, in <module>
    from .filters import api as filters
  File "D:pythonAnaconda3libsite-packagesstatsmodelstsafiltersapi.py", line 6, in <module>
    from .filtertools import miso_lfilter, convolution_filter, recursive_filter
  File "D:pythonAnaconda3libsite-packagesstatsmodelstsafiltersfiltertools.py", line 18, in <module>
    from scipy.signal.signaltools import _centered as trim_centered
ImportError: cannot import name '_centered' from 'scipy.signal.signaltools' (C:UsersAdministratorAppDataRoamingPythonPython38site-packagesscipysignalsignaltools.py)
>>> exit
Use exit() or Ctrl-Z plus Return to exit
>>> exit()

(base) C:UsersAdministrator>pip install scipy==1.6 --user -i http://pypi.douban.com/simple --trusted-host pypi.douban.co
Looking in indexes: http://pypi.douban.com/simple
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
ERROR: Could not find a version that satisfies the requirement scipy==1.6 (from versions: none)
ERROR: No matching distribution found for scipy==1.6

(base) C:UsersAdministrator>pip install scipy==1.6.0 --user -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple
Collecting scipy==1.6.0
  Downloading http://pypi.doubanio.com/packages/a1/05/9b41f6a969a0d6ad36732bdd3c936434228dafaa829932be5a51574e4958/scipy-1.6.0-cp38-cp38-win_amd64.whl (32.7 MB)
     |████████████████████████████████| 32.7 MB 3.2 MB/s
Requirement already satisfied: numpy>=1.16.5 in d:pythonanaconda3libsite-packages (from scipy==1.6.0) (1.20.3)
Installing collected packages: scipy
  Attempting uninstall: scipy
    Found existing installation: scipy 1.8.0
    Uninstalling scipy-1.8.0:
      Successfully uninstalled scipy-1.8.0
Successfully installed scipy-1.6.0

(base) C:UsersAdministrator>python
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import statsmodels.api as sm
>>>

解决后,重启jupyter notebook,进入可以正常使用。

代码语言:javascript复制
print(":".join(["CSDN叶庭云", "https://yetingyun.blog.csdn.net/"]))

0 人点赞