Importing bs4 in Python 3.5

32,881

Solution 1

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.

Solution 2

Update: BeautifulSoup 4.4.0 has been updated to be python3.5 compatible, so a pip install --upgrade beautifulsoup4 should do the trick if you are still hitting this issue.

Solution 3

I've sent the author a followup about this bug. If you want to install BeautifulSoup on Python 3.5a, I've uploaded a working patch of the source code to github.

https://github.com/jjangsangy/BeautifulSoup4

You can install it using setup.py or just copy & paste this code into terminal.

git clone https://github.com/jjangsangy/BeautifulSoup4 \
    && cd BeautifulSoup4 \
    && python3.5 setup.py install

I'm assuming here that since you're trying out 3.5a your python interpreter is installed with proper user permissions for your site-packages directory so no sudo invocation is necessary.

Share:
32,881

Related videos on Youtube

anne_t
Author by

anne_t

Updated on July 09, 2022

Comments

  • anne_t
    anne_t almost 2 years

    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\__init__.py", line 30, in    <module>
       from .builder import builder_registry, ParserRejectionMarkup
      File "C:\Python 3.5\lib\sit-packages\bs4\__init__.py", line 308, in <module>
       from . import _htmlparser
      File "C:\Python 3.5\lib\sit-packages\bs4\_htmlparser.py", line 7, in <module>
       from html.parser import ( 
    ImportError: cannot import name 'HTMLParseError'
    
  • anne_t
    anne_t about 9 years
    Thanks for the follow-up. I changed for python 3.3 and everything is working well.
  • Perkins
    Perkins about 8 years
    probably going to be pip version specific, try pip3.5 install --upgrade beautifulsoup4 or it will upgrade bs4 for your default python version (2.7 on most *nix)
  • AAAfarmclub
    AAAfarmclub over 7 years
    sudo pip3 install --upgrade beautifulsoup4
  • timothyjgraham
    timothyjgraham almost 6 years
    @AndyTerra A bit late to the party here, but this link worked for me: github.com/wention/BeautifulSoup4.git