2

[I originally posted this in serverfault, but was advised there to post it here instead.]

Matplotlib is a python library for data visualization. When I attempt to display a graph on the screen, I get the following error/warnings:

2012-12-21 16:40:05.532 python[9705:903] *** __NSAutoreleaseNoPool(): Object 0x103e25d80 of class NSCFArray autoreleased with no pool in place - just leaking
2012-12-21 16:40:05.534 python[9705:903] *** __NSAutoreleaseNoPool(): Object 0x103e26820 of class __NSFastEnumerationEnumerator autoreleased with no pool in place - just leaking
2012-12-21 16:40:05.535 python[9705:903] *** __NSAutoreleaseNoPool(): Object 0x103e9f080 of class NSObject autoreleased with no pool in place - just leaking

FWIW, one way to produce these results is shown below; all the steps shown (including the call to ipython) are taken from a matplotlib tutorial:

% ipython
...
In [1]: import matplotlib.pyplot as plt

In [2]: plt.plot([1, 3, 2, 4])
Out[3]: [<matplotlib.lines.Line2D at 0x106aabd90>]

In [3]: plt.show()

ALso, FWIW, I've observed exactly the same behavior with multiple styles of installation (on the same machine) of python+numpy+matplotlib+ipython, including installs that use the system-supplied python, those that use the python installed by homebrew, or those that use a python installed directly from source into a location off my home directory.

Any ideas of what may be going on, or what I could do about it?

4

2 回答 2

4

我遇到了同样的问题,我找到的一种解决方案是添加以下行:

plt.ion()

在第一个绘图命令之前。这将打开交互式绘图模式并且错误消息消失。这仅在命令行上绘图时对我有用,如果我在脚本中执行 ion() 然后 show() 绘图根本不会显示,如果我将 ion() 排除在外,我可以看到我的情节,但我收到错误消息。自从更新到版本 1.2.0 后才发生这种情况。

于 2013-02-13T22:23:48.393 回答
1

它试图用 Cocoa 做一些事情,但 Cocoa 并没有真正被初始化或任何东西。您可以通过在此之前运行此命令来消除错误并解决问题:

from Foundation import NSAutoreleasePool
pool = NSAutoreleasePool()

而这之后:

from AppKit import NSApplication
NSApplication.sharedApplication().run()

这需要 PyObjC。不幸的是,这可能只允许在每个 IPython 会话中显示一个图。您可能希望改用 IPython 笔记本,它消除了对 Cocoa 的依赖。

于 2012-12-22T22:25:25.057 回答