import statsmodels.api as sm 时 报错如下:
解决过程曲折,大致就是 scipy 版本与 statsmodels 的有些方法 不兼容,scipy==1.6.0后,问题解决了:
(base) C:\Users\Administrator>pipuninstallstatsmodelsFoundexistinginstallation: statsmodels0.11.1Uninstallingstatsmodels-0.11.1: Wouldremove: d:\python\anaconda3\lib\site-packages\statsmodels-0.11.1.dist-info\*d:\python\anaconda3\lib\site-packages\statsmodels\*Proceed (y/n)?ySuccessfullyuninstalledstatsmodels-0.11.1(base) C:\Users\Administrator>pipinstallstatsmodels==0.12.0-ihttp://pypi.douban.com/simple--trusted-hostpypi.douban.comLookinginindexes: http://pypi.douban.com/simpleCollectingstatsmodels==0.12.0Downloadinghttp://pypi.doubanio.com/packages/37/22/959fdc710b6b384ad21a876130000557163978880dc50e16ba5d4ce35c18/statsmodels-0.12.0-cp38-none-win_amd64.whl (9.2MB) |████████████████████████████████|9.2MB6.4MB/sRequirementalreadysatisfied: scipy>=1.1ind:\python\anaconda3\lib\site-packages (fromstatsmodels==0.12.0) (1.5.0) Requirementalreadysatisfied: numpy>=1.15ind:\python\anaconda3\lib\site-packages (fromstatsmodels==0.12.0) (1.20.3) Requirementalreadysatisfied: pandas>=0.21ind:\python\anaconda3\lib\site-packages (fromstatsmodels==0.12.0) (1.3.4) Requirementalreadysatisfied: patsy>=0.5ind:\python\anaconda3\lib\site-packages (fromstatsmodels==0.12.0) (0.5.1) Requirementalreadysatisfied: python-dateutil>=2.7.3ind:\python\anaconda3\lib\site-packages (frompandas>=0.21->statsmodels==0.12.0) (2.8.1) Requirementalreadysatisfied: pytz>=2017.3ind:\python\anaconda3\lib\site-packages (frompandas>=0.21->statsmodels==0.12.0) (2020.1) Requirementalreadysatisfied: sixind:\python\anaconda3\lib\site-packages (frompatsy>=0.5->statsmodels==0.12.0) (1.15.0) Installingcollectedpackages: statsmodelsSuccessfullyinstalledstatsmodels-0.12.0(base) C:\Users\Administrator>pipshowscipyName: scipyVersion: 1.5.0Summary: SciPy: ScientificLibraryforPythonHome-page: https://www.scipy.orgAuthor: NoneAuthor-email: NoneLicense: BSDLocation: d:\python\anaconda3\lib\site-packagesRequires: numpyRequired-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:\Users\Administrator>pipuninstallscipyFoundexistinginstallation: scipy1.5.0Uninstallingscipy-1.5.0: Wouldremove: d:\python\anaconda3\lib\site-packages\scipy-1.5.0.dist-info\*d:\python\anaconda3\lib\site-packages\scipy\*Proceed (y/n)?ySuccessfullyuninstalledscipy-1.5.0ERROR: Exception: Traceback (mostrecentcalllast): File"D:\python\Anaconda3\lib\site-packages\pip\_internal\cli\base_command.py", line188, in_mainstatus=self.run(options, args) File"D:\python\Anaconda3\lib\site-packages\pip\_internal\commands\uninstall.py", line89, inrununinstall_pathset.commit() File"D:\python\Anaconda3\lib\site-packages\pip\_internal\req\req_uninstall.py", line450, incommitself._moved_paths.commit() File"D:\python\Anaconda3\lib\site-packages\pip\_internal\req\req_uninstall.py", line290, incommitsave_dir.cleanup() File"D:\python\Anaconda3\lib\site-packages\pip\_internal\utils\temp_dir.py", line196, incleanuprmtree(self._path) File"D:\python\Anaconda3\lib\site-packages\pip\_vendor\retrying.py", line49, inwrapped_freturnRetrying(*dargs, **dkw).call(f, *args, **kw) File"D:\python\Anaconda3\lib\site-packages\pip\_vendor\retrying.py", line212, incallraiseattempt.get() File"D:\python\Anaconda3\lib\site-packages\pip\_vendor\retrying.py", line247, ingetsix.reraise(self.value[0], self.value[1], self.value[2]) File"D:\python\Anaconda3\lib\site-packages\pip\_vendor\six.py", line703, inreraiseraisevalueFile"D:\python\Anaconda3\lib\site-packages\pip\_vendor\retrying.py", line200, incallattempt=Attempt(fn(*args, **kwargs), attempt_number, False) File"D:\python\Anaconda3\lib\site-packages\pip\_internal\utils\misc.py", line135, inrmtreeshutil.rmtree(dir, ignore_errors=ignore_errors, File"D:\python\Anaconda3\lib\shutil.py", line737, inrmtreereturn_rmtree_unsafe(path, onerror) File"D:\python\Anaconda3\lib\shutil.py", line610, in_rmtree_unsafe_rmtree_unsafe(fullname, onerror) File"D:\python\Anaconda3\lib\shutil.py", line610, in_rmtree_unsafe_rmtree_unsafe(fullname, onerror) File"D:\python\Anaconda3\lib\shutil.py", line615, in_rmtree_unsafeonerror(os.unlink, fullname, sys.exc_info()) File"D:\python\Anaconda3\lib\shutil.py", line613, in_rmtree_unsafeos.unlink(fullname) PermissionError: [WinError5] 拒绝访问。: 'D:\\python\\Anaconda3\\Lib\\site-packages\\~cipy\\fft\\_pocketfft\\pypocketfft.cp38-win_amd64.pyd'(base) C:\Users\Administrator>pipinstallscipy--user-ihttp://pypi.douban.com/simple--trusted-hostpypi.douban.comLookinginindexes: http://pypi.douban.com/simpleCollectingscipyDownloadinghttp://pypi.doubanio.com/packages/56/a3/591dbf477c35f173279afa7b9ba8e13d9c7c3d001e09aebbf6100aae33a8/scipy-1.8.0-cp38-cp38-win_amd64.whl (36.9MB) |████████████████████████████████|36.9MB3.3MB/sRequirementalreadysatisfied: numpy<1.25.0,>=1.17.3ind:\python\anaconda3\lib\site-packages (fromscipy) (1.20.3) Installingcollectedpackages: scipySuccessfullyinstalledscipy-1.8.0(base) C:\Users\Administrator>pythonPython3.8.3 (default, Jul22020, 17:30:36) [MSCv.191664bit (AMD64)] :: Anaconda, Inc. onwin32Type"help", "copyright", "credits"or"license"formoreinformation. >>>importstatsmodels.apiassmTraceback (mostrecentcalllast): File"<stdin>", line1, in<module>File"D:\python\Anaconda3\lib\site-packages\statsmodels\api.py", line27, in<module>from .tsaimportapiastsaFile"D:\python\Anaconda3\lib\site-packages\statsmodels\tsa\api.py", line31, in<module>from .filtersimportapiasfiltersFile"D:\python\Anaconda3\lib\site-packages\statsmodels\tsa\filters\api.py", line6, in<module>from .filtertoolsimportmiso_lfilter, convolution_filter, recursive_filterFile"D:\python\Anaconda3\lib\site-packages\statsmodels\tsa\filters\filtertools.py", line18, in<module>fromscipy.signal.signaltoolsimport_centeredastrim_centeredImportError: cannotimportname'_centered'from'scipy.signal.signaltools' (C:\Users\Administrator\AppData\Roaming\Python\Python38\site-packages\scipy\signal\signaltools.py) >>>exitUseexit() orCtrl-ZplusReturntoexit>>>exit() (base) C:\Users\Administrator>pipinstallscipy==1.6--user-ihttp://pypi.douban.com/simple--trusted-hostpypi.douban.coLookinginindexes: http://pypi.douban.com/simpleWARNING: Therepositorylocatedatpypi.douban.comisnotatrustedorsecurehostandisbeingignored. IfthisrepositoryisavailableviaHTTPSwerecommendyouuseHTTPSinstead, otherwiseyoumaysilencethiswarningandallowitanywaywith'--trusted-host pypi.douban.com'. ERROR: Couldnotfindaversionthatsatisfiestherequirementscipy==1.6 (fromversions: none) ERROR: Nomatchingdistributionfoundforscipy==1.6(base) C:\Users\Administrator>pipinstallscipy==1.6.0--user-ihttp://pypi.douban.com/simple--trusted-hostpypi.douban.comLookinginindexes: http://pypi.douban.com/simpleCollectingscipy==1.6.0Downloadinghttp://pypi.doubanio.com/packages/a1/05/9b41f6a969a0d6ad36732bdd3c936434228dafaa829932be5a51574e4958/scipy-1.6.0-cp38-cp38-win_amd64.whl (32.7MB) |████████████████████████████████|32.7MB3.2MB/sRequirementalreadysatisfied: numpy>=1.16.5ind:\python\anaconda3\lib\site-packages (fromscipy==1.6.0) (1.20.3) Installingcollectedpackages: scipyAttemptinguninstall: scipyFoundexistinginstallation: scipy1.8.0Uninstallingscipy-1.8.0: Successfullyuninstalledscipy-1.8.0Successfullyinstalledscipy-1.6.0(base) C:\Users\Administrator>pythonPython3.8.3 (default, Jul22020, 17:30:36) [MSCv.191664bit (AMD64)] :: Anaconda, Inc. onwin32Type"help", "copyright", "credits"or"license"formoreinformation. >>>importstatsmodels.apiassm>>>
解决后,重启jupyter notebook,进入可以正常使用。
print(":".join(["CSDN叶庭云", "https://yetingyun.blog.csdn.net/"]))