The “modulenotfounderror: no module named bs4” error occurs when you try to import the “bs4” module in Python.
Yet the python interpreter cannot find the installed “bs4” module on your system.
The “bs4” is an abbreviation for “BeautifulSoup4“. Moreover, the ‘bs4‘ is a Python library which is used for web scraping, parsing HTML and XML documents.
To solve this error, you need to install the “bs4” module.
Also read the other solved error: Modulenotfounderror: no module named ‘google’ [SOLVED]
Why the modulenotfounderror: no module named ‘bs4’ error occur?
The modulenotfounderror: no module named ‘bs4’ error occur because you might able to forget to install the beautifulsoup4 module before you import it.
You might installed the beautifulsoup4 in an incorrect environment variable.
Common Error Occurs
There can be several reasons why you might encounter the “ModuleNotFoundError: No module named ‘bs4′” error. Here are a few common reasons:
- Missing Installation:
- Incorrect Module Name:
- Incorrect Python Version:
- Virtual Environment:
- Path Issues:
- Corrupted Installation:
- Incorrect Spelling:
How to solved the modulenotfounderror no module named ‘bs4’?
You can install “bs4” using pip command, which is a package manager for Python language.
Time needed: 3 minutes
Here are the solutions to solve the error modulenotfounderror no module named bs4 in a different operating system platform.
- Solution 1: Installation of
beautifulsoup4
in PythonIn your project folder root directory, Open your terminal windows or command prompt(CMD) and enter the following command to install the bs4 in Python:
pip install beautifulsoup4
After you run the following command above it will successfully install the bs4 in python
After you install the beautifulsoup4 module in windows, you may try to import it with the following code below:from bs4 import BeautifulSoup
soup = BeautifulSoup("<p>Some<b>bad<i>HTML")
print(soup.prettify()) - Solution 2: Installation of
beautifulsoup4
in Python 3In your project folder root directory, Open your terminal windows or command prompt(CMD) and enter the following command to install the
in Python 3:beautifulsoup4
pip3 install beautifulsoup4
After you execute the command above it will successfully install thebs4
in python 3: - Solution 3: Installation of
beautifulsoup4
in Server SideWhen you are getting an error in your server side. In your project folder root directory, Open your terminal windows or command prompt(CMD) and enter the following command for Installation of
beautifulsoup4
in Server Side.
For Linux:sudo pip3 install beautifulsoup4
For Windows:pip install beautifulsoup4 --user
After you run the command above it will successfully install thebs4
in python 3 on windows: - Solution 4: Installation of pip in your PATH environment variable in Python 2
If you don’t have pip install in your PATH environment variable. Type the following command below to install the pip and bs4 in your path environment.
python -m pip install beautifulsoup4
After you run the command above it will successfully install the pip andbs4
in your path environment variable:
Installation of pip in your PATH environment variable in Python 3
If you don’t have pip install in your PATH environment variable in your python 3. Type the following command below to install the pip and bs4 in your path environment.python3 -m pip install beautifulsoup4
- Solution 5: Installation of
beautifulsoup4
in py alias
In your project folder root directory, Open your terminal windows or command prompt(CMD) and enter the following command to install the beautifulsoup4 in Py Alias:py -m pip install beautifulsoup4
After you execute the command above it will successfully install the bs4 in py alias: - Solution 6: Installation of
beautifulsoup4
in Ubuntu/DebianHere is the following command to install the beautifulsoup4 in Ubuntu/Debian:
sudo apt-get install python3-bs4
- Solution 7: Installation of
beautifulsoup4
in AnacondaIn your project folder root directory, Open your terminal or anaconda command prompt(CMD) and enter the following command for Installation of beautifulsoup4 in Anaconda.
conda install -c anaconda beautifulsoup4
- Solution 8: Installation of
beautifulsoup4
in Jupyter NotebookHere is the following command to install the beautifulsoup4 in Jupyter Notebook:
!pip install bs4
Conclusion
That’s it! You should now be able to use the bs4 module in your Python projects. The above solutions can help you to solve the error Modulenotfounderror: no module named bs4 on a different operating system, you’re being used.