debian下使用Sphinx异常“Could not import extension sphinx.builders.linkcheck (exception: cannot import nam

最近使用到Sphinx编译文档,出现以下异常:python

Extension error:
Could not import extension sphinx.builders.linkcheck (exception: cannot import name SSLError)app

一开始有点摸不着头脑,明明是不能导入“sphinx.builders.linkcheck”,错误信息倒是“cannot import name SSLError”python2.7

因而使用“-P”参数在异常时打开pdb调试,pdb打印信息以下:ui

Exception occurred while building, starting debugger:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.5b1-py2.7.egg/sphinx/cmdline.py", line 295, in main
opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.5b1-py2.7.egg/sphinx/application.py", line 189, in __init__
self.setup_extension(extension)
File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.5b1-py2.7.egg/sphinx/application.py", line 514, in setup_extension
err)
ExtensionError: Could not import extension sphinx.builders.linkcheck (exception: cannot import name SSLError)url

能够看到出错的地方在“application.py”,因而打开该文件一探究竟,源码以下:命令行

进一步在pdb打印“extension”和“err”debug

如今能够知道,是在import的时候遇到了importerror,可是不知道具体是哪里错了,干脆另起python命令行,直接import这个扩展“sphinx.builders.linkcheck”,结果出现以下错误:调试

能够看到错误缘由是不能从“requests.packages.urllib3.exceptions”导入“SSLError”,经验证发现,能够在“requests.exceptions”里面导入“SSLError”blog

而网上搜索,大多也只是提到从“requests.exceptions”导入“SSLError”。因为Sphinx是刚下载的最新版,我怀疑多是版本不兼容的问题。文档

查看requests版本发现requests确实不是最新版本(官网目前最新版本为:v2.12.1):

进一步上官网确认,发现官网上有关SSLError的代码确实已经发生变化:

到此,彻底确认是requests版本更新过程当中改变了“SSLError”的位置(导入方式),升级requests到最新版后问题解决。

相关文章
相关标签/搜索