gpt4 book ai didi

python - beautifulsoup : ImportError: No module named html. 个实体

转载 作者:太空狗 更新时间:2023-10-30 00:29:44 33 4
gpt4 key购买 nike

我试图让这个模块在服务器上运行,但我在标题中收到错误:

我的脚本:

from bs4 import BeautifulSoup

当我运行它时:

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

现在,我看到了ImportError: No module named html.entities

将我重定向到 http://www.crummy.com/software/BeautifulSoup/bs4/doc/#problems-after-installation

基于此:

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...

行为没有变化:

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

我什至从修复它的服务器中删除了 python3,但同样的问题。

谁能给我指明更好的方向,卸载,重新安装?

如何确保安装了 2.7 版的代码?

干杯

亚当

最佳答案

我也遇到了这个问题。

最后,我发现这只是因为我在脚本文件的同一目录中有一个也名为“html.py”的文件。

因此,当 BeautifulSoup “from html.entities import codepoint2name”时,它抛出异常......

关于python - beautifulsoup : ImportError: No module named html. 个实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27372347/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com