Import "matplotlib" could not be resolved from source Pylance(reportMissingModuleSource)
Question:
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?
Answers:
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
https://visualstudio.microsoft.com/visual-cpp-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.
Matplotlib could not be resolved from source parlance
What to do:
- open the Command Palette (Ctrl+Shift+P)
- Type: Python: Select interpreter Here is the interpreter that worked for me!
- Navigate to your project.
- Select the latest interpreter or check what interpreter
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.
In vscode
Press 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.
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?
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
https://visualstudio.microsoft.com/visual-cpp-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.
Matplotlib could not be resolved from source parlance
What to do:
- open the Command Palette (Ctrl+Shift+P)
- Type: Python: Select interpreter Here is the interpreter that worked for me!
- Navigate to your project.
- Select the latest interpreter or check what interpreter
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.
In vscode
Press 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.