ModuleNotFoundError:没有名为“bs4”的模块,仍不工作

2024-06-17 08:59:09 发布

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

我通过命令行sudopip3installbs4和sudopip3installbeautifulsoup4在mac上下载并安装了beautifulsoup4。但是,当我尝试运行代码时:

import requests
from bs4 import BeautifulSoup

url = 'https://finance.yahoo.com/quote/AAPL?p=AAPL&.tsrc=fin-srch'

response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')

print(soup)

它给我的响应是ModuleNotFoundError:没有名为“bs4”的模块。我知道我安装了pip,并将其与python一起升级,所以我不确定为什么会发生这种情况。如果有人能解释一下,那就太好了


Tags: 代码命令行fromimporturlresponsemacrequests