Modulenotfounderror: no module named bs4 : Best Solution

Modulenotfounderror no module named bs4

Modulenotfounderror: no module named bs4 occurs if the beautifulsoup4 python module is not properly installed in the python environment. We use beautifulsoup4 for HTML data extraction, and web scraping which is quite rapid in most content-oriented application. Typically we use some code where we import beautifulsoup4 but we forgot the prerequisite to install the library and we get this error. Apart from it since we can maintain multiple python versions in the system altogether. We install the package like beautifulsoup4 but in a different interpreter/version.

Hence the root cause for the no module named bs4 error is misconfiguration of beautifulsoup4 package or improper installation of beautifulsoup4.  As a solution, we can reinstall and configure the respective package. So let’s begin.

Modulenotfounderror: no module named bs4 ( Solution ) –

The first solution will be using pip package manager.

Solution 1: Installation of beautifulsoup4 via pip –

We can install beautifulsoup4 via with single command. But we need to take care below points which slightly variate on the basis of different scenarios.

For Python 2. x version series –

pip install beautifulsoup4

For Python 3. x version series –

pip3 install beautifulsoup4
modulenotfounderror no module named bs4 solve using pip
modulenotfounderror no module named bs4 solve using pip

With Admin Rights

sudo pip install beautifulsoup4
sudo pip3 install beautifulsoup4

With Version Specification

The above command will install the latest version for beautifulsoup4 but in case your requirement is for a specific version then you can specify like below.

pip3 install beautifulsoup4==4.10.0

Here is the release history for beautifulsoup4. You can go through it if there is any version-specific requirement for you.

If pip is not configured properly –

Typically Python installers set the path for pip in the system path but in case there is some issue you can try the below command for the same as well.

python -m pip install beautifulsoup4
python3 -m pip install beautifulsoup4

Solution 2: Installation of beautifulsoup4 via conda-

Use this command if you are using conda package manager.

conda install -c anaconda beautifulsoup4
modulenotfounderror no module named bs4 solve using conda
modulenotfounderror no module named bs4 solve using conda

Solution 3: Installation of beautifulsoup4 via source code –

The above two ways are simpler than installation from the source code. It is also not too difficult but we need to download the code and install the dependencies using requirement.txt and finally, we need to run the below command.

python install
no module named bs4 solve using setup file
no module named bs4 solve using setup file

Solution 3: Installation of beautifulsoup4 via easy_install –

Here is the command to install beautifulsoup4 via easy_install.

easy_install beautifulsoup4

Solution 4: Installation of beautifulsoup4 in Linux Family Platform-

This is very specific to Linux Family OS. You can try apt-get for beautifulsoup4 installation. This will fix up the modulenotfounderror.

sudo apt-get install python3-bs4


Data Science Leaner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages, where he and his team share knowledge and help others learn more about data science.
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner