Skip to main content
 首页 » 编程设计

python之即使安装了 BeautifulSoap 的 ImportError

2024年09月07日9arxive

<分区>

我一直在尝试导入 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 bs4 和 pip 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 或任何类似的名称。有谁知道为什么会这样?我一直在寻找过去一个小时的原因:(

提前致谢!