【问题标题】:Import "matplotlib" could not be resolved from source Pylance(reportMissingModuleSource)无法从源 Pylance 解析导入“matplotlib”(reportMissingModuleSource)
【发布时间】:2022-01-14 10:47:15
【问题描述】:

每当我尝试在 VS Code 中导入 matplotlib 或 matplotlib.pyplot 时,标题中都会出现错误:

Import "matplotlib" could not be resolved from source Pylance(reportMissingModuleSource)

Import "matplotlib.pyplot" could not be resolved from source Pylance(reportMissingModuleSource)

reportMissingModuleSource 的超链接将我发送到 https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules,其中显示:
“诊断没有相应源文件的导入。当找到类型存根但模块源文件时会发生这种情况未找到,说明使用此执行环境时代码可能在运行时失败。类型检查将使用类型存根进行。”
但是,从解释中我不明白到底出了什么问题以及我应该怎么做才能解决这个问题,有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: python matplotlib visual-studio-code pylance


    【解决方案1】:

    当我选择一个不存在的python解释器matplotlib时,我可以重现你的问题:

    因此,解决方案是打开一个集成终端,然后运行pip install matplotlib。安装成功后,请重新加载窗口,警告就会消失。

    【讨论】:

      【解决方案2】:

      只需将解释器更改为左下角的 2.7.x enter image description here

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2021-04-23
      • 2022-07-28
      • 2023-01-09
      • 2022-11-19
      • 2021-09-17
      • 2021-04-18
      • 1970-01-01
      • 2021-03-23
      • 2021-03-24
      相关资源
      最近更新 更多