AttributeError: type object 'HTMLAwareEntitySubstitution' has no attribute 'preserve_whitespace_tags' error message when trying to import BeautifulSoup

2,157 views
Skip to first unread message

randytho...@u.northwestern.edu

unread,
Oct 30, 2016, 8:14:22 AM10/30/16
to beautifulsoup
I am just trying this for the first time.  I installed BeautifulSoup and html5lib.  When I try this command:  from bs4 import BeautifulSoup, I get the following error message:




---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-519-9144e80cd349> in <module>()
----> 1 from bs4 import BeautifulSoup

C:\Users\thompr1\AppData\Local\Continuum\Anaconda3\lib\site-packages\bs4\__init__.py in <module>()
     33 import warnings
     34 
---> 35 from .builder import builder_registry, ParserRejectedMarkup
     36 from .dammit import UnicodeDammit
     37 from .element import (

C:\Users\thompr1\AppData\Local\Continuum\Anaconda3\lib\site-packages\bs4\builder\__init__.py in <module>()
    226 
    227 
--> 228 class HTMLTreeBuilder(TreeBuilder):
    229     """This TreeBuilder knows facts about HTML.
    230 

C:\Users\thompr1\AppData\Local\Continuum\Anaconda3\lib\site-packages\bs4\builder\__init__.py in HTMLTreeBuilder()
    232     """
    233 
--> 234     preserve_whitespace_tags = HTMLAwareEntitySubstitution.preserve_whitespace_tags
    235     empty_element_tags = set(['br' , 'hr', 'input', 'img', 'meta',
    236                               'spacer', 'link', 'frame', 'base'])

AttributeError: type object 'HTMLAwareEntitySubstitution' has no attribute 'preserve_whitespace_tags'


I found one posting on reddit that said when they installed html5lib, their issue resolved, but mine has not.

Any thoughts?

I am using Python 3.5, Jupyter Notebook IPython version 4.2.0, windows 10

Thank you.

randytho...@u.northwestern.edu

unread,
Oct 30, 2016, 1:05:40 PM10/30/16
to beautifulsoup
This must be an Anaconda issue.  I opened up the same Jupyter notebook using Canopy, and BeautifulSoup imported without any issues.

Thanks

randytho...@u.northwestern.edu

unread,
Nov 16, 2016, 7:57:42 AM11/16/16
to beautifulsoup
Any thoughts?  I would like to install this so I can use without having to go to Canopy.

Prashant Gupta

unread,
Sep 16, 2017, 7:27:20 PM9/16/17
to 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
Reply all
Reply to author
Forward
0 new messages