【问题标题】:Can't load matplotlib.pyplot from script无法从脚本加载 matplotlib.pyplot
【发布时间】:2013-06-21 23:28:05
【问题描述】:

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

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

文件“matplotlib.py”,第 3 行,在

将 matplotlib.pyplot 导入为 plt

文件“/home/user/dir/contourf_demo.py”,第 3 行,在

将 matplotlib.pyplot 导入为 plt

ImportError: 没有名为 pyplot 的模块

我用的是Ubuntu 12.04,导入时出现问题:

将 matplotlib.pyplot 导入为 plt

我尝试过使用不同的方式来调用导入(例如 from matplotlib import pyplot),但它也不起作用。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您不能从名为 XYZ.py 的文件中导入名为 XYZ 的模块,因为 Python 会认为您正在尝试导入文件本身。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-11
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      相关资源
      最近更新 更多