Unable to import beautifulsoup in python
15,120
You installed BeautifulSoup version 3; the module is called BeautifulSoup
with capital B
and S
:
from BeautifulSoup import BeautifulSoup
See the Quickstart documentation.
You really want to upgrade to BeautifulSoup 4. BeautifulSoup 3 was discontinued in 2012.
To install version 4, use:
pip install beautifulsoup4
and import bs4
:
from bs4 import BeautifulSoup
Do study the project documentation before continuing however.
Comments
-
PieSquare almost 2 years
I'm using Python.7.10 and have installed beautifulsoup using pip. The package was installed successfully. But when I'm trying to import beautifulsoup, I'm getting this error:
ImportError: No module named beautifulsoup
I checked the list of my installed modules and I found the beautifulsoup module in the installed modules list:
-
Felipe over 6 yearsWhy do I have to import beautifulsoup4 from bs4 if the module name is beautifulsoup4? I am used to install a package and import it directly. Please, forgive me if this is a stupid a question.
-
Martijn Pieters over 6 years@Felipe: the PyPI project name is
beautifulsoup4
. The project name and the module(s) the project installs do not have to match. A project can contain more than one top-level name too. Most PyPI projects have names matching the module they install, but not all. -
Martijn Pieters over 6 years@Felipe: see Are there rules for naming single-module Python packages? for some more examples.
-
Felipe over 6 yearsThank you so much, @Martijn. I did not know that and I will take a look at the link you provided.