0

I'm on linux mint 18.3. I can import matplotlib fine, but I need to plot something from a certain file. When I try to plot something simple, I get this error:

python3 spline.py
Traceback (most recent call last):
File "spline.py", line 2, in <module>
from matplotlib.pyplot import plt
ImportError: No module named 'matplotlib'

my code in the file is:

from matplotlib.pyplot import plt

plt.plot([1, 2, 3],[2, 4, 6])

plt.show()

already tried:

pip install matplotlib
sudo apt-get install python-matplotlib
sudo apt-get install python3-matplotlib
DavidG
  • 24,279
  • 14
  • 89
  • 82
Joyce Larissa
  • 47
  • 1
  • 1
  • 7
  • did you check pythonpath? – Ricky Kim Apr 26 '19 at 14:53
  • It seems you have installed matplotlib in a different environment than you use when running the file. Else, your problem might be similar to [this](https://stackoverflow.com/questions/51055429/why-pip3-install-in-python2-sitepackages) or [this](https://stackoverflow.com/questions/31407208/pip3-4-v-refers-to-python2-7-installation). – ImportanceOfBeingErnest Apr 26 '19 at 15:33

2 Answers2

0

I think in your code you should use

import matplotlib.pyplot as plt
Xiaoyu Lu
  • 3,280
  • 1
  • 22
  • 34
0

Nevermind guys the thing was the way I was importing it, the "correct" way is:

from matplotlib import pyplot as plt

that's all now it's working

Joyce Larissa
  • 47
  • 1
  • 1
  • 7