使用BeautifulSoup导入错误

时间:2017-04-02 18:48:19

标签: python beautifulsoup bs4

我使用pip3 install beautifulsoup下载了BeautifulSoup,但效果很好。

但是当我尝试from bs4 import BeautifulSoupimport BeautifulSoup时,我会收到错误ModuleNotFoundError: No module named 'BeautifulSoup'ModuleNotFoundError: No module named 'bs4',具体取决于我使用的代码行。

我不知道出了什么问题。为什么我会收到错误?

2 个答案:

答案 0 :(得分:3)

pip3 install beautifulsoup会安装BeautifulSoup旧版本(准确地说是Beautiful Soup 3)。

您需要pip3 install beautifulsoup4pip3 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