简体   繁体   中英

ImportError No module named BeautifulSoup - path error

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>',
       '&lt;body><p id="firstpara" align="center">This is paragraph <b>one</b>.',
       '<p id="secondpara" align="blah">This is paragraph <b>two</b>.',
       '&lt;/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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM