,python,pudb"/>

首页 > 解决方案 > PUDB 错误:

问题描述

我是pudb的新手。它在大多数情况下运行良好,但是当我尝试进入一个它显然无法识别的库时,我收到以下消息:

  <no source code available>                                                                                                                                                                                                                                                                                           
  If this is generated code and you would like the source code to show up here,
  add it to linecache.cache, like

  import linecache
  linecache.cache[filename] = (size, mtime, lines, fullname)

  You can also set the attribute _MODULE_SOURCE_CODE in the module in which this function
  was compiled to a string containing the code.

我试过导入'linecache','cache'属性是一个字典。我曾尝试为缺少的模块创建一个条目几次,但均未成功。

有人可以举一个更简单和/或实用的方法将无法识别的模块添加到 pudb 的示例吗?

标签: pythonpudb

解决方案


它对我有用的方式如下。

当执行一段即时生成的代码时,我收到了这条消息。我追踪了生成代码的位置,并添加了:

import linecache
linecache.cache[__file__] = (len(source), 0, source, __file__)

(其中source变量对应于生成的源)

之后我观察到,在pudb交互模式下,堆栈列表中出现了一个新项目。这个新项目在抛出<no source code available>消息的那个之前。

当我浏览这个新项目时,我可以看到生成的源代码。


推荐阅读