Installing matplotlib on Ubuntu: ImportError


My platform:

Ubuntu 13.04, Python 2.7.4.

Installing matplotlib failed, ImportError: No module named pyplot.

I have tried many ways such as

$ sudo apt-get install python-matplotlib

and easy install, install from source..., I'm folllowing

But none of them works, This ImportError always happen, Anyone can help?

EDIT The trace back:

ImportError                               Traceback (most recent call last)
<ipython-input-4-82be63b7783c> in <module>()
----> 1 import matplotlib

/home/wuhuijia/ in <module>()
      1 import numpy as np
----> 2 import matplotlib.pyplot as plt
      3 import scipy.optimize as so
      5 def find_confidence_interval(x, pdf, confidence_level):

ImportError: No module named pyplot
7/12/2013 1:05:09 AM

Accepted Answer

Your script is named Python will first look locally when importing modules, that is, on the directory itself. Thus, Python imports your script (and not the installed matplotlib) when you execute import matplotlib.pyplot, and since your script has no submodule pyplot, it fails.

Rename your script to something else (e.g., and you should be fine.

7/12/2013 8:43:48 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow