简体   繁体   中英

how to fix ModuleNotFoundError: no module named bs4

I am trying to create a program that takes a set of numbers from a webpage and adds them up together. I used the beautifulsoup module that I installed(ran "pip install beautifulsoup4 in command prompt).

Code:

from bs4 import BeautifulSoup
web=request.urlopen('http://py4e-data.dr-chuck.net/comments_845350.html').read()
x = BeautifulSoup(html)
tags=x('span')
sum=0
for tag in tags:
    sum = sum+int(tag.contents[0])
print(sum)

However, whenever I run the program, python gives me a ModuleNotFoundError: no module named bs4. How can I fix this?

If you look here , you see that pip install beautifulsoup4 should do the job.

If you are on Linux you might have to use pip3 instead.

Do you have more than one version of Python installed on your machine?

If so, try running

pip --version

Will return something like this

pip 18.1 from c:\...\lib\site-packages\pip (python 3.6)

Then verify if you are using the same version to run your script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM