【问题标题】:cannot execute matplotlib example无法执行 matplotlib 示例
【发布时间】:2013-06-21 18:25:17
【问题描述】:

我在 Debian 7.1 上安装了 python3.2.3 并安装了numpyscipymatplotlib。当我想用基本示例测试matplotlib 时,它没有执行,也没有错误执行。这是我机器上的版本

vie@w:~$ python3
Python 3.2.3 (default, Feb 20 2013, 17:02:41)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> print (scipy.__version__)
0.10.1
>>> import numpy
>>> print (numpy.__version__)
1.7.0
>>> import matplotlib
>>> print (matplotlib.__version__)
1.2.0

vie@w:~$ python3 mpl.py
vie@w:~$ 

我想测试matplotlib(来自网站http://matplotlib.org/examples/animation/basic_example.html

什么都没有发生...

当我用 python 2.7 测试这个文件时,它工作了。

为什么我不能用 python 3 执行我的mpl.py 文件?

【问题讨论】:

  • 你的 scipy 版本比较旧,目前是 0.12。你是从哪里安装包的?

标签: numpy python-3.x matplotlib scipy


【解决方案1】:

听起来您为 python3 安装了 matplotlib,但没有构建交互式后端。

发生这种情况的原因有很多。最有可能的是 Tk 在您的 python3 安装中不可用。

当你这样做时会发生什么:

python3 -c 'import matplotlib.pyplot as plt; print(plt.get_backend())'

如果您在运行 X 服务器的机器上,您应该会看到 TkAgg(或 GtkAggQtAgg 等)。如果您看到 Agg,这意味着 matplotlib 没有使用交互式后端构建,并且安装将仅限于保存(但不显示)图形。

作为第二个测试,你可以在 python3 中运行simple hello-world Tkinter example 吗?

【讨论】:

  • 我用你的建议与 python3 -c 'import matplotlib.pyplot as plt; print(plt.get_backend())' 并作为结果得到了 Agg。我还运行了简单的 hello-world Tkinter 示例。在我安装 tk 和 tcl 后它工作了。但我的问题仍然存在。图像不是交互式的。能否请您帮助我如何使用交互式后端构建 matplotlib?
  • 如果你有Agg,你需要重新构建matplotlib。现在您已经安装了 tk 和 tcl,它应该能够识别它们的存在并构建 TkAgg 后端。
  • 成功了。在我安装 tk 和 tcl 并重建 matplotlib 之后。谢谢乔的帮助!!
猜你喜欢
  • 1970-01-01
  • 2017-02-02
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 2012-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多