Last modified: Feb 15, 2023 By Alexander Williams
3 Solutions to Solve modulenotfounderror: no module named bs4
The modulenotfounderror: no module named bs4 error appears when the program cannot import the Beatifoulsoup modules. However, this tutorial will show you three solutions To solve the error.
Solution 1: Installing BeautifulSoup packages
The first solution you need to consider is installing the BeautifulSoup packages. However, to install, choose your preferred options.
PIP:
pip install beautifulSoup4 # šļø Python 2
pip3 install beautifulSoup4 # šļø Python 3
Anaconda:
conda install -c anaconda beautifulsoup4
easy_install:
easy_install beautifulsoup4
Now execute your program again. If the problem has been solved, congratulation. If not, move to the next solution.
Solution 2: Ensure you use Python <= 3
As you know, most of the python librariesĀ no longer support Python 2 . Make sure you execute the program with Python 3 .
First of all, let's check our python version using these 2 commands:
python -V
# OR
python3 -V
If Python3 is not found on your device, Install Python on Windows, Mac, and Linux .
Solution 3: Creating virtualenv with Python <= 3
modulenotfounderror: no module named bs4 also appears when we create virtual Python 2 instead of Python 3 . So, use the following command to create your env with Python 3 .
python3 -m venv myenv
After creating the virtualenv with python 3, installĀ Beatifoulsoup again using pip3 .
Conclusion
To summarize this article, we can say that there are many solutions to solve modulenotfounderror: no module named bs4 . And the first solution that you need to do is to install the Beautiful packages.
For more about ModuleNotFoundError , Check out ModuleNotFoundError: No module named in Python .
Happy Coding ā„
Ā