如何修复ModuleNotFoundError:没有名为bs4的模块

2024-04-23 14:00:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个程序,从网页中获取一组数字并将它们相加。我使用了我安装的beautifulsoup模块(在命令提示符下运行“pip install beutifulSoup4”)

代码:

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)

但是,每当我运行程序时,python都会给我一个ModuleNotFoundError:没有名为bs4的模块。我如何修复这个问题


Tags: 模块installpip程序网页htmltagtags
2条回答

如果你看here,你会看到 pip install beautifulsoup4应该做这项工作

如果您使用的是Linux,则可能必须改用pip3

您的机器上是否安装了多个版本的Python

如果是这样,试着跑步

pip  version

会返回这样的东西吗

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

然后验证是否使用相同的版本运行脚本

相关问题 更多 >