PUDB Error: <no source code available>

641 views Asked by At

I'm new to pudb. It run fine for the most-part, but when I try to enter a library it apparently doesn't recognize, I get the following message:

  <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.

I've tried importing 'linecache' and the 'cache' attribute is a dictionary. I've tried creating an entry for the missing module a few times with no success.

Can someone please give an example on an easier and/or practical way to add an unrecognized module to pudb?

3

There are 3 answers

0
Rogério Gouvêa On

I was having this issue and in my case it was because the package was being installed as .egg, you can circumvent that installing with pip install -e foo_package

0
nikhilweee On

This answer is inspired from this GitHub issue. A possible workaround is to use the full path of the script.

Quite simply, instead of python script.py, use python /full/path/to/script.py.

This works because some libraries may use chdir to change directories and when that happens, pudb cannot locate the script, resulting in the error.

TIP: To save some keystrokes, you can simply type python $PWD/script.py instead of typing in the full path.

1
Judit Novak On

The way it worked for me is the following.

I got this message when a piece of code was executed that has been generated on-the-fly. I tracked down the location where the code was generated, and added:

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

(where the source variable corresponds to the generated source)

What I observed after, was that in pudb interactive mode, in the stack list a new item appeared. This new item was preceeding the one that throws the <no source code available> message.

When I navigate on this new item, I can see the generated source.