OS X上的matplotlib TclError

1 投票
2 回答
962 浏览
提问于 2025-04-17 05:01

我在Mac电脑上使用matplotlib,但无法生成任何动态图表。界面显示出来了,但上面没有任何图表,而且我看到出现了以下错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 245, in resize
    self.show()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 249, in draw
    tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 19, in blit
    tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
TclError

我尝试重新安装了Tcl/Tk,但结果还是一样。我还可以尝试其他什么方法吗?每次我想生成一个互动图表时都会出现这个问题,静态的(png格式)图表倒是没问题。

2 个回答

-1

我也遇到过同样的问题,后来发现是因为matplotlib和numpy这两个库的版本混合在一起导致的。之后我把它们完全卸载了,再重新安装一遍,结果一切都正常了。

1

我在使用Lion和Python 2.7的时候也遇到了同样的问题,但我的问题其实很简单,或者说有点傻;我之前安装的是适用于Mac OS 10.3的numpy和matplotlib,所以我又为正确的版本10.6重新安装了一遍,现在一切都正常了。顺便说一下,官方的安装包可以在它们各自的sourceforge页面找到。

撰写回答