Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

beautifulsoup: ImportError: No module named html.entities

Tags:

python

I am trying to get this module working on a server, and I am getting the error in the title:

My script:

from bs4 import BeautifulSoup

When I run it:

aclark@tycho ~ % python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from bs4 import BeautifulSoup
  File "/usr/lib/python2.7/site-packages/bs4/__init__.py", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "/usr/lib/python2.7/site-packages/bs4/builder/__init__.py", line 4, in <module>
    from bs4.element import (
  File "/usr/lib/python2.7/site-packages/bs4/element.py", line 5, in <module>
    from bs4.dammit import EntitySubstitution
  File "/usr/lib/python2.7/site-packages/bs4/dammit.py", line 11, in <module>
    from html.entities import codepoint2name
ImportError: No module named html.entities

Now, I have seen ImportError: No module named html.entities

Which redirects me to http://www.crummy.com/software/BeautifulSoup/bs4/doc/#problems-after-installation

Based on that:

aclark@tycho ~ % sudo pip uninstall BeautifulSoup
Uninstalling BeautifulSoup:
  /usr/lib/python2.7/site-packages/BeautifulSoup-3.2.1-py2.7.egg-info
  /usr/lib/python2.7/site-packages/BeautifulSoup.py
  /usr/lib/python2.7/site-packages/BeautifulSoup.pyc
  /usr/lib/python2.7/site-packages/BeautifulSoupTests.py
  /usr/lib/python2.7/site-packages/BeautifulSoupTests.pyc
Proceed (y/n)? y
  Successfully uninstalled BeautifulSoup`

`aclark@tycho ~ % sudo pip install BeautifulSoup
Downloading/unpacking BeautifulSoup
  Running setup.py egg_info for package BeautifulSoup

Installing collected packages: BeautifulSoup
  Running setup.py install for BeautifulSoup

Successfully installed BeautifulSoup
Cleaning up...

No change in behaviour:

aclark@tycho ~ % python test.py 
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from bs4 import BeautifulSoup
  File "/usr/lib/python2.7/site-packages/bs4/__init__.py", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "/usr/lib/python2.7/site-packages/bs4/builder/__init__.py", line 4, in <module>
    from bs4.element import (
  File "/usr/lib/python2.7/site-packages/bs4/element.py", line 5, in <module>
    from bs4.dammit import EntitySubstitution
  File "/usr/lib/python2.7/site-packages/bs4/dammit.py", line 11, in <module>
    from html.entities import codepoint2name
ImportError: No module named html.entities

I have even removed python3 from the server incase that fixed it, but same problem.

Can anyone point me in a better direction that, uninstall, re-install?

How can I make sure that the code for version 2.7 is installed?

Cheers

Adam

like image 707
Adam Clark Avatar asked Dec 09 '14 05:12

Adam Clark


2 Answers

I also met this problem.

At last, I found it's just because I have a file also named "html.py", in the same directory of the script file.

Therefore, when BeautifulSoup "from html.entities import codepoint2name", it throw exception......

like image 101
carton.swing Avatar answered Oct 09 '22 22:10

carton.swing


I ran into a similar problem under different circumstances.

pip install future

Should do the trick. Check out http://python-future.org/standard_library_imports.html for more information.

like image 5
lorg Avatar answered Oct 10 '22 00:10

lorg