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:
- Open cmd
- Type
cd path\to\your\project
- Find your virtual environment folder ("venv"/"virtualenv"/etc.)
- Find "activate" in your venv (for "venv" type in cmd
venv\Scripts\activate
) - 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).