beautifulsoup, html5lib: module object has no attribute _base

BeautifulsoupHtml5lib

Beautifulsoup Problem Overview


When I updated my packages I have this new error:

class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
AttributeError: 'module' object has no attribute '_base'

I tried to update beautifulsoup, with no more result. How can I fix that?

Beautifulsoup Solutions


Solution 1 - Beautifulsoup

I upgraded beautifulsoup4 and html5lib and it resolved the issue.

pip install --upgrade beautifulsoup4
pip install --upgrade html5lib

Solution 2 - Beautifulsoup

This is an issue with upstream package html5lib: https://bugs.launchpad.net/beautifulsoup/+bug/1603299 To fix, force downgrade to an older version:

pip install --upgrade html5lib==1.0b8

Solution 3 - Beautifulsoup

edit nov, 2017: it seems this doesn't work any more

Finally found out, a search engine didn't throw anything but it's referenced on beautifulsoup's issue tracker: https://bugs.launchpad.net/beautifulsoup/+bug/1603299

it works back with html5lib v0.9999999 (7 nines)

"html5lib<=0.9999999"

Solution 4 - Beautifulsoup

The downgrade to html5lib 1.0b8 in @Bhavuk answer works but courses a version issue with bleach.

The solution for me was with a change of version of bleach to be compatible with the new version of html5lib

pip install --upgrade bs4
pip install --upgrade bleach==1.4.2
pip install --upgrade html5lib==1.0b8

Python version 3.5

Solution 5 - Beautifulsoup

The same problem occurred on me. I don't know what you were trying to do, but it occurred on me when I tried to read XML file in pandas, using pd.read_html().

The problem is fixed by upgrading all of beautifulsoup4, html5lib, and lxml, like:

pip install bs4
pip install html5lib
pip install lxml

And restart your Python environment and now it is working.

Solution 6 - Beautifulsoup

This command solved the problem for me:

 sudo pip install html5lib==0.9999999

Solution 7 - Beautifulsoup

Just install html5lib using this because if you install the normal way then you have to spider using python2.

sudo pip3 install html5lib==0.9999999

Solution 8 - Beautifulsoup

I found trying to switch versions did not work for me. In the end, based on this issue I edited the relevant file at ~/.local/lib/python3.7/site-packages/bs4/builder/_html5lib.py for my purposes.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEhvinceView Question on Stackoverflow
Solution 1 - BeautifulsoupMattTrianoView Answer on Stackoverflow
Solution 2 - BeautifulsoupBhavuk View Answer on Stackoverflow
Solution 3 - BeautifulsoupEhvinceView Answer on Stackoverflow
Solution 4 - BeautifulsouprecurseuntilforView Answer on Stackoverflow
Solution 5 - BeautifulsoupBlaszardView Answer on Stackoverflow
Solution 6 - BeautifulsoupkavyaView Answer on Stackoverflow
Solution 7 - BeautifulsoupEkta kumar VarmaView Answer on Stackoverflow
Solution 8 - BeautifulsoupAlex Moore-NiemiView Answer on Stackoverflow