Jay Kim
Jay Kim

Reputation: 843

how do i install beautiful soup for python on my mac? see error

I'm running Mac OS X 10.7.3 on a Macbook Pro. It came with Python 2.7.1 installed. I need the beautiful soup library. So I did the following:

1) went to crummy.com and downloaded beautifulsoup4-4.0.2.tar.gz

2) uncompressed it

3) navigated to uncompressed directory and typed the following

python setup.py install

but i got a error that i couldn't write to some directory.

4) so i ran:

sudo python setup.py install

No Errors! Good, right? Not exactly. When I try to run a program with the following:

from BeautifulSoup import *

I receive the following error:

ImportError: No module named BeautifulSoup

What did I do wrong?

Thanks!

Upvotes: 6

Views: 19648

Answers (2)

Kien Truong
Kien Truong

Reputation: 11381

For BeautifulSoup4 you have to use

from bs4 import BeautifulSoup

Check the document: BS4 document

Upvotes: 13

Brian Gesiak
Brian Gesiak

Reputation: 6978

Is there a reason you can't use pip or easy_install? Unless you're set on installing from source, you can run either of the following:

$ easy_install BeautifulSoup

Or, if you have pip (which I recommend, you can install it with easy_install pip):

$ pip install BeautifulSoup

I'm not certain why your source install isn't working though. Is it possible the python interpreter you're using to install the source and the interpreter you're using in your program are different? Try running python --version on the command line--is the same version displayed as when you run the following in your program?

import sys
print sys.version  # => '2.7.2 (default, Feb  4 2012, 02:01:30)...

Upvotes: 4

Related Questions