I am trying to write a simple, local python script to do some html parsing. I installed beautifulsoup4 and imported it using
from bs4 import BeautifulSoup
But I get the error:
Traceback (most recent call last):
File "scrape_descriptions.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: No module named 'bs4'
I've tried installing BS4 in just about every way. First I did
sudo pip install BeautifulSoup4
then I tried downloading the actual files from the website and running
sudo python setup.py install
and finally I tried
sudo su
easy_install BeautifulSoup4
All of these operations appear to have completed successfully. But I'm still getting this error. I've scoured other posts but pretty much all of them are just installation instructions, which I've already done.
Typing
pip freeze
shows that bs4 is installed but running
$ python3 -i
>>> help('modules')
does not appear to list bs4.
Edit 1: Running sudo pip3 install BeautifulSoup gives this error:
Downloading/unpacking BeautifulSoup
Downloading BeautifulSoup-3.2.1.tar.gz
Running setup.py (path:/private/tmp/pip_build_root/BeautifulSoup/setup.py) egg_info for package BeautifulSoup
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/private/tmp/pip_build_root/BeautifulSoup/setup.py", line 22
print "Unit tests have failed!"
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/private/tmp/pip_build_root/BeautifulSoup/setup.py", line 22
print "Unit tests have failed!"
^
SyntaxError: invalid syntax
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /private/tmp/pip_build_root/BeautifulSoup
Storing debug log for failure in /Users/griff/.pip/pip.log
Edit 2: Solved! The reason pip3 was failing was because I was using
sudo pip3 install BeautifulSoup
instead of
sudo pip3 install BeautifulSoup4
which worked. Thanks!
The solution is:
sudo pip3 install BeautifulSoup4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With