ImportError:无法导入名称'HTMLAwareEntitySubstitution'

Son*_*hao 7 beautifulsoup python-3.5

我刚刚设置了beautifulsoup4-4.1.0并将pip升级到版本9.0.1.当我这样写:

from bs4 import BeautifulSoup
Run Code Online (Sandbox Code Playgroud)

发生错误:

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    from bs4 import BeautifulSoup
  File "D:\Program Files (x86)\Python35-32\lib\site-packages\bs4\__init__.py", line 35, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "D:\Program Files (x86)\Python35-32\lib\site-packages\bs4\builder\__init__.py", line 7, in <module>
    from bs4.element import (
ImportError: cannot import name 'HTMLAwareEntitySubstitution'
Run Code Online (Sandbox Code Playgroud)

我该怎么办?非常感谢.

小智 15

在版本你似乎有可能是一个错误bs4/builder/__init__.py.

这一行from .. import _htmlparser应该是: from . import _htmlparser

但是,我建议您在使用当前版本pip之前重新安装软件包,然后再尝试编辑源代码.

要重新安装: pip install --upgrade --force-reinstall beautifulsoup4