Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import error with BeautifulSoup

I have downloaded BeautifulSoup using pip3 install beautifulsoup and it worked fine.

But when I try from bs4 import BeautifulSoup or import BeautifulSoup, I get the error ModuleNotFoundError: No module named 'BeautifulSoup' or ModuleNotFoundError: No module named 'bs4' depending on which line of code I use.

I have no idea what's wrong. Why do I get the error?

like image 709
elmuscovado Avatar asked Apr 30 '26 08:04

elmuscovado


2 Answers

pip3 install beautifulsoup will install BeautifulSoup older version (Beautiful Soup 3 to be precise).

You need to do pip3 install beautifulsoup4 or pip3 install bs4 to install BeautifulSoup4

and then you can just use it like this :

from bs4 import BeautifulSoup

You can refer to the download page and documentation of Beautiful Soup for more understanding on this.

like image 105
Satish Prakash Garg Avatar answered May 01 '26 21:05

Satish Prakash Garg


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
like image 38
Katariina Kari Avatar answered May 01 '26 21:05

Katariina Kari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!