Importerror: No Module Named Bs4 (Beautifulsoup)

ImportError: No Module Named bs4 (BeautifulSoup)

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

ModuleNotFoundError: No module named 'bs4' [BeautifulSoup]

None of the previous answers managed to fix my error, but an ugly solution that I found was to just add the following code to the start of the file.

import subprocess
import sys

def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", bs4])

from bs4 import BeautifulSoup

Installed BeautifulSoup but still get no module named bs4

Since you are using Python 3, I think you needed to do

pip3 install BeautifulSoup4

Just pip install would have been for the Python 2 package.

Other things to check:

First make sure you ran both the BeautifulSoup install in your virtualenv, and the python3 prompt or Jupyter notebook in your virtualenv. If you did the install in your root environment and the notebook is run in your virtualenv, or vice versa, you might have a mismatch in your site-packages directory.

Ensure that your package indeed installed by typing pip3 list at a command prompt, and noting that it appeared in the list.

Check that you Jupyter notebook is indeed running a Python 3.5 kernel (upper right hand corner of the browser window)

Check that the path where the package is installed is in your sys.path

Open a Python3 prompt or in Jupyter and run

import sys
print (sys.path)

no module named bs4 whenever I try to import

Maybe the problem is that your program's project uses virtual environment (venv) without bs4. If it is so - install bs4 directly into your venv on your own:

  1. Open cmd
  2. Type cd path\to\your\project
  3. Find your virtual environment folder ("venv"/"virtualenv"/etc.)
  4. Find "activate" in your venv (for "venv" type in cmd venv\Scripts\activate)
  5. Try to install bs4 one more time.

Note: some IDEs (like PyCharm) have easier ways for it (like 'settings' button or built-in console with activated venv in it).

In your case (for PyCharm):

Variant 1

At the bottom there will be a panel with different consoles, etc:
TODO, Problems, Terminal, Python Packages, Python Console,... Open Terminal. it has to have a row like:

(venv) C:\path\to\your\PyCharmProjects\ProjectName>

Use this console to check if bs4 is installed for your project (you can just try to install one more time with pip install bs4)


Variant 2

Press Ctrl+Alt+S -> Project -> Python Interpreter

Check if bs4 is installed for your projects in the appeared packages list. If not: press "+"(button above the list), type in 'beautifulsoup' or 'bs4', choose an appropriate package and click "Install Package"

ImportError: No module named bs4?

You installed BeautifulSoup for Python 2.6, but according to your tag, you are using Python 3.x. To install explicitly for Python 3, use pip3 instead of pip, i.e.

pip3 install beautifulsoup4

No module named 'bs4' Error

I don't really see a clear way to answer your question with the information you provided, but it seems that you are not installing the bs4 package properly...

--Easy Way to Fix--

Install PyCharm:
https://www.jetbrains.com/pycharm/download/#section=windows

Once installed, configure your interpreter to use latest version of Python (install from here):
https://www.python.org/downloads/

Once you have your file open, click "File > Settings > Project Interpreter > Show All (in the drop down) > Add(+) > Add Local" and select your installed version Python. Then click the add button (+) and search for bs4 from the list of packages and install it, and you should get it working. PyCharm does everything for you, so there is really no room for error when installing packages.



Related Topics



Leave a reply



Submit