2

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 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.