Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 619
Jay Kim Avatar asked Mar 26 '12 16:03

Jay Kim


People also ask

How do I install BeautifulSoup in Python?

To use beautiful soup, you need to install it: $ pip install beautifulsoup4 . Beautiful Soup also relies on a parser, the default is lxml . You may already have it, but you should check (open IDLE and attempt to import lxml). If not, do: $ pip install lxml or $ apt-get install python-lxml .

How do I install beautiful soup in terminal?

To install Beautifulsoup on Windows, Linux, or any operating system, one would need pip package. To check how to install pip on your operating system, check out – PIP Installation – Windows || Linux. Wait and relax, Beautifulsoup would be installed shortly.


2 Answers

For BeautifulSoup4 you have to use

from bs4 import BeautifulSoup

Check the document: BS4 document

like image 104
Kien Truong Avatar answered Oct 08 '22 23:10

Kien Truong


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)...
like image 39
modocache Avatar answered Oct 09 '22 00:10

modocache