解决Python报错: AttributeError: 'module' object has no attribute '_base'

来源:互联网 发布:java iocp 编辑:程序博客网 时间:2024/05/20 03:08
#完整报错File "/usr/lib/python2.7/dist-packages/bs4/builder/_html5lib.py", line 70, in <module>    class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):AttributeError: 'module' object has no attribute '_base'

方法1

pip  install --upgrade html5lib==1.0b8

方法2

vi /usr/lib/python2.7/dist-packages/bs4/builder/_html5lib.py 70Gclass TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder)

需要加载_base.py文件,而这个文件在/usr/local/lib/python2.7/dist-packages/html5lib/treebuilders下没有,
这里写图片描述
把base.py换成_base.py
更新一下ok!

后记

以前经常遇到这种问题只是一味的Google,没有认真分析原因,及时解决了也无法知道其中的原理,得到一个教训:报错先看源码,再解决,行不通再去google!

阅读全文
0 0