Oleh: rennypradina | Maret 28, 2009

Installing Beautiful Soup

(I was originally intending to write, “OMG, Python is so wonderful!”. But then I came to. :-D )

I wanted to install Beautiful Soup, a module in Python for parsing HTML. There was no quite explicit step-by-step guide on how to do it, just that I should put the file (which file? BeautifulSoup3.0.7a.py?) in Python library or in my working directory. I decided to put it in C:\Python26\Lib\, since it was where urllib2 (another Python module) was. Doing this in the Python interpreter:

>>> from BeautifulSoup import BeautifulSoup

yields:

Traceback (most recent call last):
File “”, line 1, in
from BeautifulSoup import BeautifulSoup
ImportError: No module named BeautifulSoup

so I decided to try putting it in C:\Python26\Lib\site-packages, since it was where non-bundle Python modules are to be stored, according to several websites. (I had Python Image Library there.) But it just didn’t work, again.

I didn’t remember having any such problem when my OS was Ubuntu…. Oh yes, it was because there was ‘easy-install’. Easy it was, indeed.

So I thought, maybe because the name of the file was not BeautifuSoup.py, but rather, BeautifulSoup3.0.7a.py. I decided to truncate the version part of the name, and performing >>> from BeautifulSoup import BeautifulSoup again.

Guess what? It worked! (At least, no more error message. :-) )

If it does indeed work, then no wonder that there is no explicit how-to for installing BeautifulSoup. It *is* as easy as that.

However, I notice that in the C:\Python26\Lib\site-packages folder there is now a compiled BeautifulSoup file. Could it be that if I run the BeautifulSoup3.0.7a first, effecting in the creation of a compilation of Beautiful Soup, I don’t need to truncate the file’s name? What method would be ‘right’? Is it both?


Beri tanggapan

Your response:

Kategori