I'm trying to run a simple code in Pycharm Community Edition 4.5.3 to display a graph with some points using matplotlib
import matplotlib.pyplot as plt
plt.plot([5,4,4,4,6,6,7,7,8,8,9,10,10,10,10,11,11,12,12,13],
[5,7,10,13,8,14,7,11,5,13,9,4,6,12,14,8,10,6,13,8], 'ro')
plt.plot([6,7],[8,7],'bo-')
plt.axis([0, 15, 0, 15])
plt.show()Although matplotlib is installed properly Pycharm is not recognizing it. I'm getting this error message on running the above code in Pycharm
1ImportError: No module named 'matplotlib'
3 Answers
it seems like you have installed python more than one and matplotlib library installed with python that currently not used by Pycharm by default. so in your python script add #!/usr/bin/env python
or full path of python interpreter that has matplotlib.
if you are using python installed by system by default then use python-matplotlib if you install python3-matplotlib then it will create problem or vise versa . in this situation you have to mention full path of python interpreter that you want to use .
i just installed only python-matplotlib using
sudo apt-get install python-matplotliband able to run code using
python test.py Install the package python-matplotlib
sudo apt-get install python-matplotlibor for Python3
sudo apt-get install python3-matplotlib I think your problem like mine.
I tested import matplotlib in python shell, it is OK.
But shows error in Pycharm.
This is because Pycharm don't know the path of site-packages.
- You should add path of site-packages (for me C:\Program Files\Python 3.5\lib\site-packages) to PATH or
In your code add these
import sys sys.path.append(r"C:\Program Files\Python 3.5\lib\site-packages") import matplotlib.pyplot as plt
I think it will help you :)