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

whenever I try to import matplotlib or matplotlib.pyplot in VS Code I get the error in the title:

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

or

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

The hyperlink of the reportMissingModuleSource sends me to https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules, where it says:
"Diagnostics for imports that have no corresponding source file. This happens when a type stub is found, but the module source file was not found, indicating that the code may fail at runtime when using this execution environment. Type checking will be done using the type stub."
However, from the explanation I don't understand exactly what's wrong and what I should do to fix this, can someone help me with this?



Solution 1:[1]

I can reproduce your question when I select a python interpreter where doesn't exist matplotlib:

enter image description here

So, the solution is opening an integrated Terminal then run pip install matplotlib. After it's installed successfully, please reload window, then the warning should go away.

Solution 2:[2]

Just changes the interpreter to 2.7.x in left-bottom corner enter image description here

Solution 3:[3]

I have the same issue - I did two things and its working now

Restart the app and run again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Molly Wang-MSFT
Solution 2 Ruben Tanahara
Solution 3 SauZ Khan