[python] ImportError: No Module Named bs4 (BeautifulSoup)

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.

This question is related to python beautifulsoup flask importerror

The answer is


The easiest is using easy_install.

easy_install bs4 

It will work if pip fails.


I did what @rayid-ali said, except I'm on a Windows 10 machine so I left out the sudo. That is, I did the following:

python3 -m pip install bs4

and it worked like a pycharm. Worked like a charm anyway.


Addendum to the original query: modules.py

help('modules')

$python modules.py

It lists that module bs4 already been installed.

_codecs_kr          blinker             json                six
_codecs_tw          brotli              kaitaistruct        smtpd
_collections        bs4                 keyword             smtplib
_collections_abc    builtins            ldap3               sndhdr
_compat_pickle      bz2                 lib2to3             socket

Proper solution is:

pip install --upgrade bs4

Should solve the problem.

Not only that, it will show same error for other modules as well. So you got to issue the pip command same way as above for those errored module(s).


pip3.7 install bs4

Try this. It works with python 3.7


A lot of tutorials/references were written for Python 2 and tell you to use pip install somename. If you're using Python 3 you want to change that to pip3 install somename.


I will advise you to uninstall the bs4 library by using this command:

pip uninstall bs4

and then install it using this command:

sudo apt-get install python3-bs4

I was facing the same problem in my Linux Ubuntu when I used the following command for installing bs4 library:

pip install bs4


If you use Pycharm, go to preferences - project interpreter - install bs4.

If you try to install BeautifulSoup, it will still show that no module named bs4.


Try reinstalling the module OR Try installing with beautiful soup with the below command

pip install --ignore-installed BeautifulSoup4

pip3 install BeautifulSoup4

Try this. It works for me. The reason is well explained here..


You might want to try install bs4 with

pip install --ignore-installed BeautifulSoup4

if the methods above didn't work for you.


For python2.x:

sudo pip install BeautifulSoup4

For python3:

sudo apt-get install python3-bs4

In case you are behind corporate proxy then try using following command

pip install --proxy=http://www-YOUR_PROXY_URL.com:PROXY_PORT BeautifulSoup4


pip install --user BeautifulSoup4


Just tagging onto Balthazar's answer. Running

pip install BeautifulSoup4

did not work for me. Instead use

pip install beautifulsoup4

If you are using Anaconda for package management, following should do:

conda install -c anaconda beautifulsoup4


I have been searching far and wide in the internet.

I'm using Python 3.6 and MacOS. I have uninstalled and installed with pip3 install bs4 but that didn't work. It seems like python is not able to detect or search the bs4 module.

This is what worked: python3 -m pip install bs4

The -m option allows you to add a module name.

https://docs.python.org/3/using/cmdline.html


Try this:

sudo python3 -m pip install bs4

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to beautifulsoup

Scraping: SSL: CERTIFICATE_VERIFY_FAILED error for http://en.wikipedia.org What should I use to open a url instead of urlopen in urllib3 TypeError: a bytes-like object is required, not 'str' in python and CSV UnicodeEncodeError: 'ascii' codec can't encode character at special name UnicodeEncodeError: 'charmap' codec can't encode characters bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? Using BeautifulSoup to extract text without tags python BeautifulSoup parsing table install beautiful soup using pip Python BeautifulSoup extract text between element

Examples related to flask

Flask at first run: Do not use the development server in a production environment Flask - Calling python function on button OnClick event python-How to set global variables in Flask? In Flask, What is request.args and how is it used? How to print from Flask @app.route to python console What does "app.run(host='0.0.0.0') " mean in Flask Making an asynchronous task in Flask Flask ImportError: No Module Named Flask can you add HTTPS functionality to a python flask web server? How to get http headers in flask?

Examples related to importerror

ImportError: libSM.so.6: cannot open shared object file: No such file or directory "ImportError: no module named 'requests'" after installing with pip ImportError: cannot import name main when running pip --version command in windows7 32 bit Why can't Python import Image from PIL? ImportError: No module named 'bottle' - PyCharm Installing OpenCV for Python on Ubuntu, getting ImportError: No module named cv2.cv How can I troubleshoot Python "Could not find platform independent libraries <prefix>" "ImportError: No module named" when trying to run Python script ImportError: DLL load failed: %1 is not a valid Win32 application ImportError: No module named six