1

I wish to inspect the code inside a (pip installed) module that I've imported (called transformers if it is relevant). So right now what I am doing is putting breakpoint() where relevant in the site_package location and calling the module inside test.py.

from transformers import AutoModel, AutoTokenizer, EncoderDecoderModel

However, Ideally I wish to set and remove breakpoints on the fly as I inspect the code, as I could normally do with a python module I wrote. Wondering if there is something similar for external libraries.

Alternate Solution

I would equally be happy if I could write breakpoint() where I need it to be on the fly. I used to do this with Jupyter with my own modules by adding the following two lines:

%load_ext autoreload
%autoreload 2

However, this did not work for an external library when I added in new breakpoints.

sachinruk
  • 9,571
  • 12
  • 55
  • 86

2 Answers2

2

Use an IDE such as PyCharm or Visual Studio Code.

I use Jetbrains CLion that allows me to view external libraries code by right clicking -> Go To -> Declaration or usage.

See this answer.

To do your breakpoint() function, you will have to modify the external library code.

As mentionned here, you should never modify an external library code. Alternatively, with an IDE you will be able to put breakpoints by clicking the line where you want to put a breakpoint.

But if you still want to edit the code, you should install the module with the -e option.

Pommepomme
  • 115
  • 1
  • 11
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 19 '21 at 12:46
2

You can add "justMyCode": false, in the launch.json file as the default value of it is true.

You can refer to here for more details.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
  • this works OK for regular Python files, but did not hel wiht Jupyter. Perhaps there are some additional parameters needed in `launch.json`. I tested with jupyter running in WSL. – Poe Dator Jul 29 '23 at 23:29