2
votes

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.

1

1 Answers

5
votes

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.