2

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?

JS.
  • 14,781
  • 13
  • 63
  • 75
  • What do you mean by 'unrecognized module'? Could you give an example? – MegaIng Aug 08 '18 at 21:19
  • In my case, it's module (PhidgetsPython/Phidgets/Devices/InterfaceKit.py) located in another directory. The script has no problem importing the module, but pudb apparently can't see it. I tried adding that directory to my PYTHONPATH, but it does not appear to have helped. – JS. Aug 08 '18 at 23:03

3 Answers3

2

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.

  • 1
    What about code that is **not** generated? I'm getting this for the first time after using pudb for several years without incident. None of the code is generated. Anything special I need to know about Python3? First time debugging Py3 script. Interesting note: I normally use set_trace() strategically located, rather than entering the debugger using "python3 -m pudb ..." However, when I do that, it hits the set_trace() breakpoint and there is no source. If, instead, I enter the debugger using '-m pudb' and then hit continue, which then stops at the set_trace(), the source appears. – tanager Jan 17 '20 at 23:46
0

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.

nikhilweee
  • 3,953
  • 1
  • 18
  • 13
0

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