Reputation: 133
I've downloaded beautiful soup to use in python and all was fine but it shows this error:
from BeautifulSoup import BeautifulSoup ImportError: No module named BeautifulSoup
after a good google and search on here I tried
from bs4 import BeautifulSoup
but get essentially the same error.
ImportError: No module named bs4
The code I am trying to execute is below.
from BeautifulSoup import BeautifulSoup
import re
doc = ['<html><head><title>Page title</title></head>',
'<body><p id="firstpara" align="center">This is paragraph <b>one</b>.',
'<p id="secondpara" align="blah">This is paragraph <b>two</b>.',
'</html>']
soup = BeautifulSoup(''.join(doc))
print soup.prettify()
I've installed beautifulsoup4 and I'm using mac OS X if that counts for anything
EDIT as a few comments said, I had a spelling error however after correcting this the same error is still being thrown up despite having the correct spelling.
EDIT I've tried to use lxml as an alternative and it gives me the same error just with lxml, I had the same problem with requests too so I'm assuming its a problem with an incorrect path rather than the import itself hence the slight title change
EDIT as requested output of which -a python:
/usr/local/bin/python
/usr/bin/python
Upvotes: 1
Views: 3591
Reputation: 473863
from BeautifulSoup import BeautifulSoup
This is how you import the BeautifulSoup
in beautifulsoup version 3.
And, since you have installed the beautifulsoup4
package, you need to change your import to:
from bs4 import BeautifulSoup
And, you need to make sure you have beautifulsoup4
installed in the same exact Python environment you are using to execute the script.
Upvotes: 2