16

I have spent the past 45 minutes hopelessly trying to run:

from bs4 import BeautifulSoup

But to no avail. I have tried the commands:

python -m pip install beautifulsoup4

where it says:

Requirement already satisfied: beautifulsoup4 in c:\python27\lib\site-packages

I have tried:

pip3 install beautifulsoup4

where it says the same.

I have tried:

pip install beautifulsoup4

Same thing.

I have looked all over stackoverflow, youtube, I am driving myself insane trying to figure this out. I have no idea what to do, please help me.

When I try to run my program main.py with the following code:

from bs4 import BeautifulSoup

With py -3 main.py, I get the error:

ModuleNotFoundError: No module named 'bs4'

Please please please please help me.

I have tried the method proposed at BeautifulSoup4 can't be installed in python3.5 on Windows7 but to no avail.

Community
  • 1
  • 1
Cooby Booby
  • 303
  • 1
  • 2
  • 7

8 Answers8

17

Now there is beautifulsoup4 for Python 3.6. It's the same, am using it this way on my webcrawl project.

Just add the beautifulsoup4 module to the project. Then try the line

from bs4 import BeautifulSoup
Darshan
  • 173
  • 4
13

As of now the module is not getting loaded to python3.6 Try This

python3.6 -m pip install beautifulsoup4
shahin
  • 3,515
  • 1
  • 17
  • 17
  • This one should've worked. Sohaibs comment is useless I have py 3.6.1 it works. If this doesn't work I'll post a solution that has it's pros n cons. – innicoder May 08 '17 at 02:04
  • Simple `python -m pip ...` worked for me with version 3.7. – AbreQueVoy Jul 05 '18 at 13:34
  • There is a message in __init.py__ file : `'You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'!='You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).' ` – piepi Jul 25 '18 at 18:53
5

I went through something similar but managed to install BeautifulSoup4. I tried running the commands suggested but none of it worked. So here's what I did.

On the command prompt, I decided to try running the commands on the python scripts directory

cd C:\Users\User\AppData\Local\Programs\Python\Python36-32\Scripts

then

pip3 install BeautifulSoup4

You should see something that says

Collecting BeautifulSoup4
 Downloading beautifulsoup4-4.6.0-py3-none-any.whl (86kB)
   100% |████████████████████████████████| 92kB 6.7kB/s
Installing collected packages: BeautifulSoup4
Successfully installed BeautifulSoup4-4.6.0

Hope this helps.

xandra
  • 51
  • 1
  • 1
1

Just install this instead: https://anaconda.org/ (This is what we use at work to manage imports).

It's basically Python with the top 100 modules all installed. The only downside is size (300 MB).

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99
  • Was able to install BeautifulSoup 4.6.0 for Python 3.6 using Anaconda: `conda install beautifulsoup4`. Anaconda's pkg ref.: `beautifulsoup4: 4.6.0-py36_0`. Specific Python version: 3.6.2. *Note*: I installed BS4 into a python virtual env. – noobninja Aug 08 '17 at 22:43
1

Just install:

pip3 install bs4 --user

Import in code:

from bs4 import BeautifulSoup
import requests

res = requests.get(url)
soup = BeautifulSoup(res.content,"html.parser")
Akshay
  • 39
  • 5
0

The problem is that while it installed beautifulsoup4 and several libraries are not supported on Python 3.6 at the moment.

You have two options. You can either use a virtual environment like Anaconda or virtualenv as Alan suggested. Here you will make an environment and set the python version to 3.5

The other option is to uninstall python 3.6 and install 3.5 and then beautifulsoup4

0

I was getting this same error on a mac and the problem stemmed from using Python 2.7.10 when I thought I was using 3.7.

python test.py

File "test.py", line 1, in <module>
    from bs4 import BeautifulSoup
ImportError: No module named bs4

However when I was explicit about what python version I wanted to use everything worked. So on the terminal use python and then your version number. Example my version is 3.7:

python3.7 test.py
user3325126
  • 1,284
  • 4
  • 15
  • 36
0

Thanks noobninja,

As for extending Python 3.8 to BeautifulSoup4, only using ANACONDA worked with me (using MAC OS).

  1. Download Anaconda for Mac OS (more than 2 GB)
  2. In terminal: test Anaconda installation:

    $ conda list

  3. $ conda install beautifulsoup4
  4. Run Python3 shell
  5. type : from bs4 import BeautifulSoup

No error message !

zmag
  • 7,825
  • 12
  • 32
  • 42