Monday, November 12, 2012

Converting BeautifulSoup 4 for Python 3


According to BeautifulSoup homepage, the latest release (Beautiful Soup 4.1.3) is compatible for both Python 2.x and Python 3.x. However, to use BS 4 in Python 3.x, you will need to manually convert the code using 2to3.

Windows 7:


Download BS 4.


cd C:\beautifulsoup4-4.1.3
python C:\Python33\Tools\Scripts\2to3.py -w bs4
python setup.py install

**-w option means overwriting the original file



Ubuntu 12.04:


** Setup proxy if you need to.


wget http://www.crummy.com/software/BeautifulSoup/bs4/download/beautifulsoup4-4.1.3.tar.gz
tar -xvzf beautifulsoup4-4.1.3.tar.gz
2to3 -w beautifulsoup4-4.1.3/bs4
cd beautifulsoup4-4.1.3/
sudo python3 setup.py install


To check if BS4 was properly installed, type in your Python 3 interpreter: 

>>> from bs4 import BeautifulSoup

1 comment:

  1. This was immensely helpful. For those who try this and can't open python from Command Promt, check out this link to fix it: http://stackoverflow.com/questions/4621255/how-do-i-run-a-python-program-in-the-command-prompt-in-windows-7

    ReplyDelete