【问题标题】:ModuleNotFoundError: No module named 'requests' even though I have the module installedModuleNotFoundError: No module named \'requests\' 即使我安装了模块
【发布时间】:2022-10-22 01:07:15
【问题描述】:

对不起,措辞不好的标题。

我使用命令pip install requests 安装了python 模块请求,现在它可以工作了,但是几天后我打开了vs 代码并得到了这个错误

 ModuleNotFoundError: No module named 'requests'

所以我使用了pip uninstall requests 然后pip install requests 它仍然给了我我在Windows 11 Visual Studio Code python 3.10 上的错误(这发生在所有模块上,而不仅仅是请求)

【问题讨论】:

  • vscode 可能没有使用正确的 python 环境。 code.visualstudio.com/docs/python/environments
  • 尝试在你的IDE中配置python路径,Ctrl+Shift+P并搜索select interpreter并配置python路径
  • 尝试使用python3pip3 命令
  • 我建议使用virtualenv 并激活它,这样您就可以始终确定您使用的是正确的python 和解释器。它还有助于保持您的主要 python 安装干净的.

标签: python


【解决方案1】:

您需要检查 vscode 使用的 python 解释器,并确保它使用的是您安装并由 pip 使用的解释器

使用来自 vscode 的默认解释器,请求模块被标记为不可用,它将返回错误 enter image description here

enter image description here

查看语言选择器旁边的 vscode 按钮右侧部分。在那里你会看到 {} python,它旁边是当前的 python 解释器 单击它并选择正确的python解释器

enter image description here

按照 vscode 文档更改默认解释器,这样您就不必每次在项目中打开文件时都更新它。 https://code.visualstudio.com/docs/python/environments#:~:text=your%20User%20Settings.-,To%20do%20so%2C%20open%20the%20Command%20Palette%20(Ctrl%2BShift ,设置%2C%20和%20%20合适的%20解释器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 2022-11-08
    • 1970-01-01
    • 2018-06-12
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多