ImportError: No module named matplotlib.pyplot

I am currently practicing matplotlib. This is the first example I practice.

#!/usr/bin/python

import matplotlib.pyplot as plt

radius = [1.0, 2.0, 3.0, 4.0]
area = [3.14159, 12.56636, 28.27431, 50.26544]

plt.plot(radius, area)
plt.show()

When I run this script with python ./plot_test.py, it shows plot correctly. However, I run it by itself, ./plot_test.py, it throws the followings:

Traceback (most recent call last):
File "./plot_test.py", line 3, in <module>
  import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot

Does python look for matplotlib in different locations?

The environment is:

Mac OS X 10.8.4 64bit
built-in python 2.7

numpy, scipy, matplotlib is installed with:

sudo port install py27-numpy py27-scipy py27-matplotlib \
py27-ipython +notebook py27-pandas py27-sympy py27-nose

20 Answers
20

Leave a Comment