无法从脚本加载matplotlib.pyplot

Rog*_*ana 2 python matplotlib

我正在尝试从matplotlib文档中运行contourf示例.当我从python shell运行它时,一切运行良好,但是当我将它作为脚本(python contourf_demo.py)运行时,会出现以下错误:

Traceback(最近一次调用最后一次):

文件"matplotlib.py",第3行,in

将matplotlib.pyplot导入为plt

文件"/home/user/dir/contourf_demo.py",第3行,in

将matplotlib.pyplot导入为plt

ImportError:没有名为pyplot的模块

我正在使用Ubuntu 12.04,导入问题时:

将matplotlib.pyplot导入为plt

我尝试使用不同的方法来调用导入(例如来自matplotlib import pyplot),但它既不起作用.

jab*_*edo 5

您无法从名为XYZ.py的文件中导入名为XYZ的模块,因为Python会解释您尝试导入文件本身.

将文件从matplotlib.py更改为其他任何内容.