Home > Software engineering >  no module named bs4 whenever I try to import
no module named bs4 whenever I try to import

Time:10-04

I am attempting to create a web scraping program but whenever I write: from bs4 import beautifulsoup, I always get the error: no module named bs4. I installed bs4 by: pip install beautifulsoup4 and pip install bs4 but nothing is working. Thanks!

CodePudding user response:

Maybe check out if your machine even installed it with:

import bs4 

bs4.__version__

Then run:

import bs4 as bs

If it's still not working look at pip itself and re-install it:

pip --version

sudo pip uninstall pip

sudo easy_install pip

CodePudding user response:

It works

#!/usr/bin/python3
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
from urllib.request import urlopen

data = urlopen('https://my_site/').read()
read_data = BeautifulSoup(data)

CodePudding user response:

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

  • Related