Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm trying to run the contourf example from the matplotlib documentation. When I run it from a python shell, everything works well, but when I run it as a script (python contourf_demo.py), the following error rises:

Traceback (most recent call last):

File "matplotlib.py", line 3, in

import matplotlib.pyplot as plt

File "/home/user/dir/contourf_demo.py", line 3, in

import matplotlib.pyplot as plt

ImportError: No module named pyplot

I'm using Ubuntu 12.04, and the problem comes when importing:

import matplotlib.pyplot as plt

I have tried using different ways to call the import (such as from matplotlib import pyplot), but it doesn't work neither.

share|improve this question
up vote 3 down vote accepted

You can't import a module named XYZ from a file called XYZ.py, because Python would interpret that you are trying to import the file itself.

Change your file from matplotlib.py to anything else.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.