[SOLVED] ModuleNotFoundError: No module named bs4

If you’re receiving a ModuleNotFoundError: No module named ‘bs4’ error when trying to import the bs4 module, it means that the Beautiful Soup library is not installed in your Python environment.

To resolve this issue, you can install the bs4 library using pip, the Python package installer.

Error Message:

dev@codetryout:~$ python3 web_scrapper.py
Traceback (most recent call last):
  File "web_scrapper.py", line 2, in <module>
    from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'


You can install the module BeautifulSoup using:

pip3 install BeautifulSoup4


dev@codetryout:~$ pip3 install BeautifulSoup4
Collecting BeautifulSoup4
  Downloading beautifulsoup4-4.12.2-py3-none-any.whl (142 kB)
........... 142 kB 7.2 MB/s
Collecting soupsieve>1.2
  Downloading soupsieve-2.4.1-py3-none-any.whl (36 kB)
Installing collected packages: soupsieve, BeautifulSoup4
Successfully installed BeautifulSoup4-4.12.2 soupsieve-2.4.1
pip3 install BeautifulSoup

After the installation is complete, try importing bs4 in your Python script or interactive shell:

from bs4 import BeautifulSoup

If there are no errors, the installation was successful, and you can now use Beautiful Soup in your code.

If you’re using a virtual environment, activate the environment before running the pip3 install command to ensure that Beautiful Soup is installed within the correct environment.