Python,摆脱 BS4?

问题描述 投票:0回答:1

如果我们访问:https://pypi.org/project/bs4/我们可以阅读:

这是一个由 Beautiful Soup 的开发者管理的虚拟包,用于防止域名抢注。 PyPI 的 BeautifulSoup Python 包的正式名称是 beautifulsoup4。这个包确保如果你错误地输入 pip install bs4,你最终会得到 Beautiful Soup。

因此,在 python 中给出以下行:

from bs4 import BeautifulSoup, Comment
如何将其替换为
beautifulsoup4
?即我根本不想安装 bs4 软件包,因为它只是声称的虚拟软件包...

python beautifulsoup pip python-import python-packaging
1个回答
3
投票

分发包和它包含的导入包不一定具有相同的名称。换句话说,您安装的内容不一定与您导入的内容具有相同的名称。尽管惯例是赋予它们相同的名称,但也有例外。而“美丽的汤”就是一个例外。

因此,您在命令行上运行

python -m pip install beautifulsoup4
,但在 Python 代码中编写
import bs4

话虽如此,您也许可以安全地卸载

bs4

python -m pip uninstall bs4

只要您还安装了

beautifulsoup4

python -m pip install beautifulsoup4
python -m pip show beautifulsoup4
© www.soinside.com 2019 - 2024. All rights reserved.