python - 即使安装了 BeautifulSoap 的 ImportError

标签 python pip importerror

<分区>

我一直在尝试导入 BeautifulSoap(Beautiful Soap 4,而不是 3)

从 bs4 导入 BeautifulSoap

但我不断收到 ImportError:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'BeautifulSoap'

我已经通过 pip 安装了 BeautifulSoap4,通过 pip install bs4pip install --upgrade --force-reinstall beautifulsoup4。出于某种原因,pip install beautifulsoap4 给我:

Could not find a version that satisfies the requirement beautifulsoap4 (from versions: )
No matching distribution found for beautifulsoap4

无论如何,只需使用 import bs4 导入 bs4 就不会出现任何错误。我的 Python 文件都没有命名为 bs4.py 或 beautifulsoap.py 或任何类似的名称。有谁知道为什么会这样?我一直在寻找过去一个小时的原因:(

提前致谢!

最佳答案

pip install bs4pip install beautifulsoap4 都不会安装 BeautifulSoup (Soup != Soap)

命令是 pip install beautifulsoup4

from bs4 import BeautifulSoup

检查 Docs

如果你通过pip搜索名称,你可以看到: pip 搜索 bs4:

bs4 (0.0.1) - Dummy package for Beautiful Soup

pip search beautifulsoup4

beautifulsoup4 (4.6.0) - Screen-scraping library

关于python - 即使安装了 BeautifulSoap 的 ImportError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50049523/

相关文章:

python - ImportError: No module... 在 python setup.py install 之后

python - 带有 FancyArrowPatch 的虚线

python - 如果测试在覆盖范围内运行,是否可以让 py.test 跳过测试?

当其他数组为 NaN 时,Python 2D 数组将值替换为 NaN

python - groupby 在搜索 View 中的多对多关系字段上?

python - 如何使用 Python pip 安装 google.cloud?

python - 没有名为 'pip._internal' 的模块; 'pip' 不是包

python:使用不正确的导入语句导入模块=>来自生成的 ImportError 的不详尽信息

python - 安装成功后找不到pip包

python - 无法在 virtualenv 中导入包