Reputation: 67
I know this question is asked a lot, I searched for the last three hours for an answer, but couldn't solve my problem.
As soon as I try to:
import matplotlib.pyplot as plt
my Visual Studio Code IDE tells me that: Unable to import 'matplotlib.pyplot'
My current version of Python is:
Python 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
as you can see, I used the Anaconda package, hence matplotlib should be included. I am Using Mac OS 10.15.2
If I enter
import matplotlib.pyplot as plt
it does import that, however, as soon as I try a basic example, like
x = [1,2,3]
y = [2,4,1]
plt.plot(x, y)
I obtain:
[<matplotlib.lines.Line2D object at 0x10c23d950>]
And a blank token in my Dashboard pops up, which I can only force to quit.
In the course of trying to solve this problem, I tried anything I saw that was related to this topic, although I did not understand everything of it. I hope I did not make a real damage. My last step was completely deinstalling anaconda and reinstalling.
Thanks for taking your time!
Upvotes: 2
Views: 15018
Reputation: 1
I just had the same problem and this worked for me in a jupyter notebook in vs code. I ran this as its own cell before running the cell with all my imports. I had to do this for another package in the past. Not sure why the normal method of pip install in the vs code terminal didn't work but at least this worked:
import sys
!{sys.executable} -m pip install matplotlib
Upvotes: 0
Reputation: 1586
Having come here with this error myself, especially if you're using VS Code you need to make sure that the version of Python you're running in VS Code is the same one that's running on your OS. Otherwise, you can conda install
or pip3 install
all you want into the OS, but VS Code and Jupyter Notebooks won't know anything about those modules. There are a few ways to figure this out, but mostly it's making sure that the Python version you see when typing python --version
in the terminal matches the interpreter shown in the top-right corner of your VS Code window.
Upvotes: 0
Reputation: 111
First you need to install package matplotlib using conda console in your project
conda install -c conda-forge matplotlib
You also can install package using PIP
python -m pip install -U matplotlib
And Finally import your package in your source code
import matplotlib.pyplot as plt
Or another Way you can import
from matplotlib import pyplot as plt
Upvotes: 1
Reputation: 545
The module can be imported, but your IDE says module not found
, means your linter (vscode uses pylinter) is not configured correctly.
Start PyLint from correct anaconda environment in Visual Studio Code
Upvotes: 1