我使用pip3 install beautifulsoup
下载了BeautifulSoup,但效果很好。
但是当我尝试from bs4 import BeautifulSoup
或import BeautifulSoup
时,我会收到错误ModuleNotFoundError: No module named 'BeautifulSoup'
或ModuleNotFoundError: No module named 'bs4'
,具体取决于我使用的代码行。
我不知道出了什么问题。为什么我会收到错误?
答案 0 :(得分:3)
pip3 install beautifulsoup
会安装BeautifulSoup旧版本(准确地说是Beautiful Soup 3
)。
您需要pip3 install beautifulsoup4
或pip3 install bs4
来安装BeautifulSoup4
然后你可以像这样使用它:
from bs4 import BeautifulSoup
您可以参考Beautiful Soup
的{{3}}和download page了解更多信息。
答案 1 :(得分:0)
I had the same problem and what solved it for me was to upgrade pip3.
Try this from this thread comment
pip3 install --upgrade pip
And if that does not work, there is another way to upgrade it that I found from this post
curl https://bootstrap.pypa.io/get-pip.py | python3