Ubuntu - How to install a Python module (BeautifulSoup) on Python 3.3 instead of Python 2.7?

dragonmnl picture dragonmnl · Oct 22, 2014 · Viewed 69.8k times · Source

I have this code (as written in BS4 documentaion):

  from bs4 import BeautifulSoup

When I run the script (using python3) I get the error:

  ImportError: No module named 'bs4'

So installed BeatifulSoup by:

  sudo pip install BeatifulSoup4

But when I try to run the script again I get the same error. Indeed BS4 is installed in:

  BeautifulSoup4 in /usr/local/lib/python2.7/dist-packages

But I want to install and use it with python3.3 (as there are other module which are not working with python2.7).

I tried with:

  virtualenv --python=/usr/bin/python2.7 /usr/bin/python3.3

and then install BS4 again, but nothing solved.

Any clue? Thanks in advance

Answer

jrwren picture jrwren · Nov 7, 2014

Ubuntu has beautifulsoup packaged. I found it by running apt-cache search

$ apt-cache search beautifulsoup

I see it has both a 2.7 and 3.3 version in the results. You can get the 3.3 version by installing python3-bs4

$ sudo apt-get install python3-bs4