importerror: no module named html.parser

11,387

Solution 1

BeautifulSoup documentation is pretty clear about it:

If you get the ImportError “No module named html.parser”, your problem is that you’re running the Python 3 version of the code under Python 2.

Solution 2

@alecxe's answer didn't help in my case. For me, it turned out that I had accidentally downloaded an earlier version of BeautifulSoup either because I was using pip (rather than pip3) or because the link on crummy.com (aptly named) pointed me to a site directory of an old version of BeautifulSoup that Python3 doesn't support anymore... hence the import error.

If you are in my situation: you'll find that the error message points you to a directory in /Library/Frameworks/Python.framework/.../lib/site-packages. Remove all folders related to bs4 and then follow the same instructions for your .tar.gz found in the link on crummy.com (above) (python[X] setup.py install), but this time, get your stinking latest tarball from https://www.crummy.com/software/BeautifulSoup/bs4/download/

Share:
11,387
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    Eclipse + python 2.7 when i use from bs4 import BeautifulSoup, an error occur The error list is following:

    Traceback (most recent call last):
      File "D:\SDK\SampleTest\FileSearch\src\logic\__init__.py", line 8, in <module>
        from bs4 import BeautifulSoup
      File "D:\Program Files\Python27\lib\site-packages\bs4\__init__.py", line 29, in <module>
        from .builder import builder_registry
      File "D:\Program Files\Python27\lib\site-packages\bs4\builder\__init__.py", line 279, in <module>
        from . import _htmlparser
      File "D:\Program Files\Python27\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
        from html.parser import HTMLParser
    ImportError: No module named html.parser