Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'bs4' Error

I planned to do web scraping, but I seem to be stuck on very first step.

import urllib.request
from bs4 import beautifulSoup

wiki = "https://en.wikipedia.org/wiki/List_of_state_and_union_territory_capitals_in_India"

page = urllib.urlopen(wiki)

soup = BeautifulSoup(page)

print(soup.prettify())

I wrote these line just to test, but it shows an error that

Traceback (most recent call last):
  File "C:/python programs/Web Scraping/wiki.py", line 3, in <module>
    from bs4 import beautifulSoup
ModuleNotFoundError: No module named 'bs4'


Process finished with exit code 1

Things which i tried to clear it.

1) pip install beautifulsoup4 (tried this with easy_install as well)

2) check the python path in environment variable. i have included both C:\python and C:\python\Scripts in paths.

3) Tried downloading Beautiful Soup from crummy.com and then install from `python setup.py install command.

I spent almost whole day clearing this out, tried almost every solution and its literally frustrating now. but if anyone still wants to mark it as duplicate you are free to do so.

is there anything i have missed ?

like image 896
gochi Avatar asked Oct 19 '25 14:10

gochi


1 Answers

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.

like image 180
Omar Barazanji Avatar answered Oct 21 '25 03:10

Omar Barazanji