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)
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?
Just changes the interpreter to 2.7.x in left-bottom corner enter image description here
I have the same issue – I did two things and its working now
Check if there is some earlier versions of python installed on your machine – if yes then remove and reinstall the latest one
Second install the Microsoft C++ Build Tools
Restart the app and run again.
I was getting the same problem and realised the package install path for my active virtual env wasn’t listed in sys.path
after appending this location to sys.path my .ipynb was able to import matplotlib
I experienced a similar issue even after installing vs_BuildTools.
What to do:
I had the same issue. Sometimes it’s back to multiple versions of python on your device. You just need to change the path. Make sure the correct Python interpreter is selected in your IDE.
CTRL + Shift + P or (
⌘ + Shift + P on macOS) to open the command palette. Then type
Python select interpreter in the search field and choose the right version.
VSCode terminal does not activate your venv right after it is created. You might have installed the package to your computer instead of venv you use.
Try close VSCode terminal and repoen. Virtual environment might be active and try to install the package again.
Check this part and change it to correct interpreter.