即使安装了也很重要

2024-05-18 18:22:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试进口BeautifulSoap(美丽的肥皂4,而不是3)

from bs4 import BeautifulSoap

但我一直有一个很重要的问题:

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

我已经通过pip install bs4和{}安装了带有pip的BeautifulSoap4。不知为什么,pip install beautifulsoap4给了我:

^{pr2}$

不管怎样,只要用import bs4导入bs4就不会出错。我的Python文件都没有命名为bs4.py或美丽soap.py或者任何类似的东西。有人知道为什么会这样吗?过去一小时我一直在寻找原因:(

提前谢谢!在


Tags: installpipfrompyimportmoststdincall
2条回答

pip install bs4和{}都没有安装BeautifulSoup(Soup!=肥皂)

命令是 pip install beautifulsoup4

from bs4 import BeautifulSoup

检查Docs

如果按pip搜索名称,可以看到: pip搜索bs4:

bs4 (0.0.1) - Dummy package for Beautiful Soup

^{pr2}$

beautifulsoup4 (4.6.0) - Screen-scraping library

您用BeautifulSoup键入错误

正确的是from bs4 import BeautifulSoup

相关问题 更多 >

    热门问题