ImportError:没有名为请求的模块:但已安装]]

问题描述 投票:0回答:3

我正在尝试使用python学习网络抓取。我使用pip3 install requests安装了请求,然后使用相同的命令再次检查了请求。我从终端获得以下输出

Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages

但是当我尝试执行以下代码时

from bs4 import BeautifulSoup
import requests

with open('/home/aca/Documents/Python files/test.html') as html_file:
    soup = BeautifulSoup(html_file, 'lxml')
print(soup.prettify())

在atom ide(版本1.26.1)中,我收到以下错误消息。

Traceback (most recent call last):
  File "/home/aca/Documents/Python files/experiment.py", line 2, in <module>
    import requests
ImportError: No module named requests
[Finished in 0.167s]

我已通过使用python shell导入IDLE并在没有ImportError的情况下完成了任务,确认在IDLE上安装了请求。我被困在这一点上。这是我的Atom ide的旧版本的问题吗?如果是,请为lubuntu 18.04推荐一个轻量级的想法。

我正在尝试使用python学习网络抓取。我使用pip3安装请求安装了请求,并使用相同的命令再次检查了请求。我从终端Require ... ...获得了以下输出:

尝试检查python版本。您很有可能在一个解释器中安装了模块请求,而Atom使用了另一个解释器。直接在命令行中运行脚本。
python python-3.x python-requests atom-editor
3个回答
1
投票

您是否安装了多个版本的Python?

尝试一下:
python3.6 -m pip install requests

您还可以在运行此experiment.py脚本时验证Atom是否选择了正确的解释器。

如果普通的pip3命令不起作用,请尝试sudo python3 -m pip install requests


1
投票
© www.soinside.com 2019 - 2024. All rights reserved.