无法从源 Pylance 解析导入“matplotlib”(reportMissingModuleSource)

Sjo*_*oll 13 python matplotlib visual-studio-code pylance

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

Import "matplotlib" could not be resolved from source Pylance(reportMissingModuleSource)
Run Code Online (Sandbox Code Playgroud)

或者

Import "matplotlib.pyplot" could not be resolved from source Pylance(reportMissingModuleSource)
Run Code Online (Sandbox Code Playgroud)

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

Mol*_*SFT 21

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

在此输入图像描述

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


小智 5

我遇到过同样的问题。有时,您的设备上会返回多个版本的 python。你只需要改变路径。确保在 IDE 中选择了正确的 Python 解释器。

\n

按或 (vscode在macOS 上)打开命令面板。然后在搜索字段中输入并选择正确的版本。CTRL + Shift + P\xe2\x8c\x98 + Shift + PPython select interpreter

\n