Reputation: 55
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.
Upvotes: 1
Views: 2306
Reputation: 41
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:
cd path\to\your\project
venv\Scripts\activate
)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"
Upvotes: 1
Reputation: 11
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)
Upvotes: 1
Reputation: 1049
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
Upvotes: 0