24

I am trying to set a breakpoint in an external Python module in VS code.

I have tried editing the source file and inserting import pdb; pdb.set_trace() where I want the breakpoint.

This enters the pdb command line debugger rather than the debugger in the VS Code GUI.

How do I set a breakpoint in an imported Python module so that I enter the VS Code debugger?

RobinL
  • 11,009
  • 8
  • 48
  • 68

2 Answers2

27

Marvin's suggestion appears to be sufficient:

add a launch configuration "justMyCode":false . See code.visualstudio.com/docs/python/debugging#_justmycode

sivano
  • 619
  • 1
  • 6
  • 12
3

You need to import the folder containing the source code of the imported module into the project, using file -> add folder to workspace. In my case this was /Users/robinl/anaconda3/lib/python3.6/site-packages/great_expectations/

Within VS code, you can then navigate to the file you want to debug and set a breakpoint by clicking to the left of the code as normal.

RobinL
  • 11,009
  • 8
  • 48
  • 68
  • 8
    Also, you may need to add a launch configuration ```"justMyCode":false``` . See https://code.visualstudio.com/docs/python/debugging#_justmycode – Marvin Dec 31 '19 at 16:53
  • 1
    Answer given by @Marvin appears to me to be the only necessary step (just tried and it worked) – sivano May 12 '20 at 12:02
  • 2
    In VS code version 1.51.0 Marvin's answer is enuf, no need to import the folder! @sivano you should post that as an answer here, the current accepted answer is overkill. – chrisinmtown Nov 17 '20 at 13:05
  • This was the only solution that worked for me! Setting `"justMyCode": false` was not enough in my case. Thank you so much! – Blubsiwubsi Jun 23 '22 at 16:47