ImportError: No Module Named bs4 (BeautifulSoup)
Solution 1
Activate the virtualenv, and then install BeautifulSoup4:
$ pip install BeautifulSoup4
When you installed bs4
with easy_install
, you installed it system-wide. So your system python can import it, but not your virtualenv python.
If you do not need bs4
to be installed in your system python path, uninstall it and keep it in your virtualenv.
For more information about virtualenvs, read this
Solution 2
For python2.x:
sudo pip install BeautifulSoup4
For python3:
sudo apt-get install python3-bs4
Solution 3
Just tagging onto Balthazar's answer. Running
pip install BeautifulSoup4
did not work for me. Instead use
pip install beautifulsoup4
Solution 4
Try this:
sudo python3 -m pip install bs4
Solution 5
pip3 install BeautifulSoup4
Try this. It works for me. The reason is well explained here..
Related videos on Youtube
harryt
Updated on July 08, 2022Comments
-
harryt almost 2 years
I'm working in Python and using Flask. When I run my main Python file on my computer, it works perfectly, but when I activate venv and run the Flask Python file in the terminal, it says that my main Python file has "No Module Named bs4." Any comments or advice is greatly appreciated.
-
Asfar Hussain Siddiqui about 2 yearspip3 install BeautifulSoup4
-
combinatorist about 2 yearsLol, my problem was pipenv installing bs4 with ipython as dev packages and then later reinstalling without including dev. Moving it to prod packages worked.
-
-
Balthazar Rouberol over 11 yearsImagine (for the example sake) that you're working on a project that requires a specific version of a module. You might also be working on a different project, requiring a different version of this module. If each project is located in virtualenvs, you will have two absolutely independent python environments, instead of having a system python environment with two versions of the same module. Keep your system env clean. Work in virtualenvs.
-
Suraj almost 8 yearsThe official site
crummy.com
failed to providepython3-bs4
package name. -
questionasker almost 7 yearsI cannot install, get error
locale.Error: unsupported locale setting
Do you have any idea ? -
Balthazar Rouberol almost 7 yearsI can't truly guess without a traceback, but have a look at stackoverflow.com/questions/14547631/…
-
blamblambunny almost 5 yearsAlso remember that if you're using a venv, you have to use the python binary from that venv.
/usr/bin/python
(on a Mac OS) is wrong; it should be<your path to your venv>/bin/python
-
ishandutta2007 over 4 yearsfor python 3 too
sudo pip install BeautifulSoup4
works -
Eoin about 4 yearsI had to exit() Python so that the PIP install would work :)
-
PatrickT almost 4 yearsThe option "-c anaconda" is the default, so "conda install beautifulsoup4" does the same and is easier to memorize :-)
-
M. Junaid Salaat about 2 yearsyou, my friend are a lifesaver
-
Siddiqui Noor almost 2 yearsThis works for me running Python 3.6 on iMac in the year 2022.