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!
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 .
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.
For BeautifulSoup4 you have to use
from bs4 import BeautifulSoup
Check the document: BS4 document
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)...
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