anne_t anne_t - 1 year ago 465
Python Question

Importing bs4 in Python 3.5

I have installed both Python 3.5 and Beautifulsoup4. When I try to import bs4, I get the error below. Is there any fix for that? Or should I just install Python 3.4 instead?
Please be very explicit - I am new to programming. Many thanks!

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python 3.5\lib\sit-packages\bs4\", line 30, in <module>
from .builder import builder_registry, ParserRejectionMarkup
File "C:\Python 3.5\lib\sit-packages\bs4\", line 308, in <module>
from . import _htmlparser
File "C:\Python 3.5\lib\sit-packages\bs4\", line 7, in <module>
from html.parser import (
ImportError: cannot import name 'HTMLParseError'

Answer Source

Update: Starting with 4.4.0, BeautifulSoup is compatible with Python 3.5. Upgrade:

pip install --upgrade beautifulsoup4

Old answer:

Because of the changes made for Deprecate strict mode of HTMLParser issue:

Issue #15114: the strict mode and argument of HTMLParser, HTMLParser.error, and the HTMLParserError exception have been removed.

I'm afraid beautifulSoup4 is not compatible with Python 3.5 at the moment. Use Python 3.4.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download