Jupyter 笔记本中的 %debug - 访问丢失的回溯帧



当我尝试用%debug在Jupyter Notebook中调试我的代码时,我点击了"最旧的帧"。

> $HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py(244)_xy_from_xy()
242         if x.shape[0] != y.shape[0]:
243             raise ValueError("x and y must have same first dimension, but "
--> 244                              "have shapes {} and {}".format(x.shape, y.shape))
245         if x.ndim > 2 or y.ndim > 2:
246             raise ValueError("x and y can be no greater than 2-D, but have "
ipdb> up
> $HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py(385)_plot_args()
383             x, y = index_of(tup[-1])
384 
--> 385         x, y = self._xy_from_xy(x, y)
386 
387         if self.command == 'plot':
ipdb> up
> $HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py(407)_grab_next_args()
405                 return
406             if len(remaining) <= 3:
--> 407                 for seg in self._plot_args(remaining, kwargs):
408                     yield seg
409                 return
ipdb> up
*** Oldest frame

问题是异常的回溯要长得多:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-c0be78c78358> in <module>()
----> 1 _ = plotSensitivity('inverse_corelation_uniform_log_boost_serial_smooth_lite', 1)
<ipython-input-51-c479a5eeae49> in plotSensitivity(dataset, threshold)
75                      truePositives * 100,
76                      label=method,
---> 77                      ls=LS[method[0]])
78 
79         plt.xscale('log')
$HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
3315                       mplDeprecation)
3316     try:
-> 3317         ret = ax.plot(*args, **kwargs)
3318     finally:
3319         ax._hold = washold
$HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1896                     warnings.warn(msg % (label_namer, func.__name__),
1897                                   RuntimeWarning, stacklevel=2)
-> 1898             return func(ax, *args, **kwargs)
1899         pre_doc = inner.__doc__
1900         if pre_doc is None:
$HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
1404         kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
1405 
-> 1406         for line in self._get_lines(*args, **kwargs):
1407             self.add_line(line)
1408             lines.append(line)
$HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
405                 return
406             if len(remaining) <= 3:
--> 407                 for seg in self._plot_args(remaining, kwargs):
408                     yield seg
409                 return
$HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
383             x, y = index_of(tup[-1])
384 
--> 385         x, y = self._xy_from_xy(x, y)
386 
387         if self.command == 'plot':
$HOME/anaconda3/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
242         if x.shape[0] != y.shape[0]:
243             raise ValueError("x and y must have same first dimension, but "
--> 244                              "have shapes {} and {}".format(x.shape, y.shape))
245         if x.ndim > 2 or y.ndim > 2:
246             raise ValueError("x and y can be no greater than 2-D, but have "
ValueError: x and y must have same first dimension, but have shapes (5,) and (500,)

其他软件包也会发生同样的情况(例如patsystatsmodels使用(。

如何使用调试器中的代码访问帧?

不幸的是,我认为您在 ipython 中遇到了一个长期存在的错误,它无法通过生成器调试调用堆栈。

有关详细信息,请参阅 https://github.com/ipython/ipython/issues/6251。 我怀疑这是他们隐藏最后一帧(将在 ipython 内部(的逻辑的结果,但没有确凿的证据证明这一点。

在他们修复它之前,您可以使用import pdb; pdb.pm()而不是魔法来解决问题。

相关内容

  • 没有找到相关文章

最新更新