【问题标题】:import requests is showing error in python but it is showing in pip3 list导入请求在 python 中显示错误,但它显示在 pip3 列表中
【发布时间】:2020-04-18 23:23:39
【问题描述】:

如果我尝试安装请求,则显示已满足要求,但如果我尝试导入,则会引发错误。

Traceback (most recent call last):
File "", line 1, in 
ModuleNotFoundError: No module named 'requests'.

我正在运行命令 pip3 list 然后它显示请求 2.23.0。但不是 可以导入。

【问题讨论】:

  • 你能分享完整的错误吗?
  • pythonyouareusing -m pip intall requests 然后python your_script.py - 您的 pip3 与您正在运行的 python 不匹配。
  • 这能回答你的问题吗? Dealing with multiple Python versions and PIP?
  • Apples-MacBook-Pro:withoutrest apple$ python3 test.py Traceback(最近一次调用最后):文件“test.py”,第 1 行,在 导入请求中 ModuleNotFoundError:没有模块命名'requests' Apples-MacBook-Pro:withoutrest apple$ python3 test.py Traceback(最近一次调用最后):文件“test.py”,第 1 行,在 导入请求中 ModuleNotFoundError:没有名为“requests”的模块但是如果我运行 pip3 list 然后它显示请求版本 Apples-MacBook-Pro: without rest apple$ pip3 list Package Version requests 2.23.0 @Shakeel
  • 它现在是否向您显示它未能加载的 python 路径?正如#modesitt 所建议的,您需要在您正在使用的python 下安装软件包。最佳实践是创建 virtualenv 并在那里安装你的依赖项。

标签: python django python-3.x django-models python-requests


【解决方案1】:

从共享错误链接中,我可以注意到您的系统中安装了两个 python 版本,并且您在 python3.7 上安装了requests(即/usr/local/lib/python3.7/site-packages)并尝试在python3.8上安装import requests

解决方案:要么在 python3.8 上安装 requests(我猜应该是 pip3.8 install requests)要么从 python3.7 运行你的脚本

【讨论】:

    猜你喜欢
    • 2020-06-04
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 2013-10-30
    相关资源
    最近更新 更多