【问题标题】:Python ImportError: No module named requests when requirements are already satisfiedPython ImportError:已满足要求时没有名为请求的模块
【发布时间】:2021-05-31 19:05:21
【问题描述】:

我正在使用 Linux 服务器环境并尝试执行简单的 python 脚本。

#!/usr/bin/env python

import os
import requests

执行后我得到这个错误:

File "./tele.py", line 4, in <module>
    import requests
ImportError: No module named requests

我尝试了所有可能的选项,还搜索了早期的线程来解决问题,但遗憾的是到目前为止没有任何效果

我尝试过的选项:

安装虚拟环境并尝试 pip install 请求。

pip install requests

另外,尝试卸载全局请求库并仅在虚拟环境中安装。

它也正在安装并给我如下消息:

  Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
     |################################| 61 kB 31.3 MB/s
Requirement already satisfied: chardet<5,>=3.0.2 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (4.0.0)
Requirement already satisfied: idna<3,>=2.5 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (2020.12.5)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (1.26.2)
Installing collected packages: requests
Successfully installed requests-2.25.1

另外,尝试在我的脚本中强制添加 python3 但这也不起作用

尝试了另一种选择:

import urllib3.requests

pip 列表显示模块请求,

requests              2.25.1
requests-oauthlib     1.3.0
requests-toolbelt     0.8.0
requests-unixsocket   0.1.5

我的 python 版本是:

Python -V -> Python 2.7.17
Python3 -V -> Python 3.6.9
pip -V -> pip 21.0 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
pip3 -V -> pip 21.0 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

谁能帮我解决这个问题?

-PD

【问题讨论】:

  • #!/usr/bin/env python
  • 如果您在虚拟环境中工作,则需要在环境激活后安装requests 包。看起来你为 3.6 的系统解释器安装了 requests

标签: python python-3.x pip python-requests python-module


【解决方案1】:

谢谢。问题已通过安装解决。

 sudo apt-get install python-requests --upgrade

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-08
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多