ImportError: No Module Named bs4 (BeautifulSoup)

397,844

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..

Share:
397,844

Related videos on Youtube

harryt
Author by

harryt

Updated on July 08, 2022

Comments

  • harryt
    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
      Asfar Hussain Siddiqui about 2 years
      pip3 install BeautifulSoup4
    • combinatorist
      combinatorist about 2 years
      Lol, 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
    Balthazar Rouberol over 11 years
    Imagine (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
    Suraj almost 8 years
    The official site crummy.com failed to provide python3-bs4 package name.
  • questionasker
    questionasker almost 7 years
    I cannot install, get error locale.Error: unsupported locale setting Do you have any idea ?
  • Balthazar Rouberol
    Balthazar Rouberol almost 7 years
    I can't truly guess without a traceback, but have a look at stackoverflow.com/questions/14547631/…
  • blamblambunny
    blamblambunny almost 5 years
    Also 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
    ishandutta2007 over 4 years
    for python 3 too sudo pip install BeautifulSoup4 works
  • Eoin
    Eoin about 4 years
    I had to exit() Python so that the PIP install would work :)
  • PatrickT
    PatrickT almost 4 years
    The option "-c anaconda" is the default, so "conda install beautifulsoup4" does the same and is easier to memorize :-)
  • M. Junaid Salaat
    M. Junaid Salaat about 2 years
    you, my friend are a lifesaver
  • Siddiqui Noor
    Siddiqui Noor almost 2 years
    This works for me running Python 3.6 on iMac in the year 2022.