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?
Set breakpoints in source code To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
Just use python -m pdb <your_script>. py then b <line_number> to set the breakpoint at chosen line number (no function parentheses). Hit c to continue to your breakpoint. You can see all your breakpoints using b command by itself.
If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.
If you delete all the breakpoints from your code at any time, you can easily import them by just clicking on the “ Import “ breakpoints button. This will restore all of your saved breakpoints. Note: Breakpoint Import depends on the line number where you have set your breakpoint earlier.
Marvin's suggestion appears to be sufficient:
add a launch configuration
"justMyCode":false
. See code.visualstudio.com/docs/python/debugging#_justmycode
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With