izeko
Posts: 16
Joined: Tue May 22, 2012 1:45 pm

No module named bs4

Mon Nov 12, 2018 10:31 pm

Hi

I am trying to run a script that uses beautiful soup, but I get error 'no module named bs4'

First line of code is:
From bs4 import Beautifulsoup

Python version is 2.7.13
OS: raspbian

I installed beautiful with:
Pip install beautifulsoup4
Pip install bs4

Does it make a difference what path I run the above. Have tried in same folder as python and where my script is.

Also tried a few other things I have seen online but nothing seems to work.

Can anybody help or point me in the right direction.

Thanks

User avatar
DougieLawson
Posts: 42313
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: No module named bs4

Mon Nov 12, 2018 10:38 pm

Why are you using python2, it's a much better idea to use python3 for everything.

To install BS4 use sudo pip install beautifulsoup4; sudo pip3 install beautifulsoup4 to get it for both python versions.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

izeko
Posts: 16
Joined: Tue May 22, 2012 1:45 pm

Re: No module named bs4

Mon Nov 12, 2018 11:09 pm

Thanks for the reply

I have also tried using pip3, and i still got same error. I am using python 2 as it came with raspbian os. Is there and easy way of upgrading this?

Thanks

User avatar
DougieLawson
Posts: 42313
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: No module named bs4

Mon Nov 12, 2018 11:19 pm

BOTH python2 (aka python) and python3 are installed with Raspbian Stretch.

Run python 3.6 programs with the python3 command.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

izeko
Posts: 16
Joined: Tue May 22, 2012 1:45 pm

Re: No module named bs4

Mon Nov 12, 2018 11:27 pm

I think I have installed an older version raspbian. I will try with stretch.

Thanks

DirkS
Posts: 10804
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: No module named bs4

Tue Nov 13, 2018 8:46 am

Make sure you install modules globally using 'sudo pip' or 'sudo pip3'.
In general you should not use 'sudo' to start your scripts.

Return to “Python”