【发布时间】:2011-10-28 04:45:05
【问题描述】:
编辑
很遗憾,目前这是不可能的。我发现它是bug in Spyder。开发者是still figuring out how to approach this。
目标
在调试代码时可视化数据(我也想使用 Spyder!)。
尝试 #1:从 Spyder 的 IPython 运行 foo.bar
-
使用以下代码创建一个名为 foo.py 的文件:
from ipdb import set_trace as st import matplotlib.pyplot as plt def bar(): st() -
在 IPython 中,键入以下内容:
In [4]: import foo In [5]: foo.bar() --Return-- None > somewhere_over_the_rainbow\foo.py(5)bar() 3 4 def bar(): ----> 5 st() ipdb> plt.plot([1, 2], [3, 4]) [<matplotlib.lines.Line2D object at 0x05CA8E90>] ipdb> plt.show()
情节仍处于“冻结”状态。如果我退出调试器,绘制更新。如果我尝试关闭绘图,IPython 会崩溃。显然两者都是不可取的,也不允许我在调试时看到数据。
尝试 #2:从命令行从 IPython 运行 foo.bar
- 使用与尝试 #1 中相同的 foo.py:
-
从命令行打开 IPython:
In [4]: import foo In [5]: foo.bar() --Return-- None > somewhere_over_the_rainbow\foo.py(5)bar() 3 4 def bar(): ----> 5 st() ipdb> plt.plot([1, 2], [3, 4]) [<matplotlib.lines.Line2D object at 0x03904070>] ipdb> plt.show()
程序按我的预期显示情节。但我想使用 Spyder。
尝试 #3:从命令行从 IPython 运行 baz.bar
-
编写baz.py:
from ipdb import set_trace as st import matplotlib.pyplot as plt st() -
从命令行打开 IPython:
In [4]: import baz --Return-- None > somewhere_over_the_rainbow\baz.py(4)<module>() 2 import matplotlib.pyplot as plt 3 ----> 4 st() ipdb> plt.
然后 Spyder 完全冻结。
有什么建议吗?
注意 #1:在我的完整代码中,我有许多文件和许多函数,因此在一个没有函数的脚本中将它们混合在一起是不可行的。
注意 #2:使用任何 matplotlib 交互命令(例如 ion()、interactive(True) 等)均无效。
注意事项 #3:Spyder 版本 2.0.12、Python 2.6、matplotlib 1.0.1。
【问题讨论】:
-
C:\Python26\lib\site-packages\matplotlib\__init__.py:888: UserWarning: This call to matplotlib.use() has no effect because the the backend has already been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time. if warn: warnings.warn(_use_error_msg) -
In [3]: matplotlib.get_backend() Out[3]: 'Qt4Agg' -
你有什么版本的matplotlib?
-
谢谢,能够将其更改为 TkAgg。同样的问题发生了。
plt.plot()创建了图形,但内容为白色(即里面没有写任何内容);plt.show()什么都不做;exit()导致 Spyder 冻结。 -
@eryksun 让我们continue this discussion in chat
标签: python debugging matplotlib pdb spyder