21

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

2

5 Answers 5

45

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
11

Use pip3

sudo pip3 install BeautifulSoup4

If you cannot run pip3 install it with the following:

sudo apt-get install python3-setuptools
sudo easy_install3 pip 


xxx@Ubuntu14:~/Desktop$ sudo pip3 install BeautifulSoup4
[sudo] password for xxx:
Downloading/unpacking BeautifulSoup4
  Downloading beautifulsoup4-4.3.2.tar.gz (143kB): 143kB downloaded
  Running setup.py (path:/tmp/pip_build_root/BeautifulSoup4/setup.py) egg_info for package BeautifulSoup4

Installing collected packages: BeautifulSoup4
  Running setup.py install for BeautifulSoup4
    Skipping implicit fixer: buffer
    Skipping implicit fixer: idioms
    Skipping implicit fixer: set_literal
    Skipping implicit fixer: ws_comma

Successfully installed BeautifulSoup4
Cleaning up...
xxx@Ubuntu14:~/Desktop$ python3
Python 3.4.2 (default, Oct  8 2014, 13:08:17)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
>>> 
0
5

A single command did the trick for me:

Try:

sudo apt-get install python3-bs4

and then import it as:

from bs4 import BeautifulSoup    
1

I have often referenced the documentation link: https://docs.python.org/3/installing/

Some examples:

 python2   -m pip install SomePackage  # default Python 2 
 python2.7 -m pip install SomePackage  # specifically Python 2.7 
 python3   -m pip install SomePackage  # default Python 3 
 python3.4 -m pip install SomePackage  # specifically Python 3.4
0
0

I had the same problem, but when I tried to "sudo apt-get install'python3-bs4" it said it was already installed. I ran my program with "python3 program.py" and it worked just fine.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.