Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set breakpoint in imported python module in vs code

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?

like image 436
RobinL Avatar asked Aug 06 '19 09:08

RobinL


People also ask

How do you use breakpoint in VS code?

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.

How do you set a breakpoint in a python script?

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.

How do I Debug Python code in VSCode?

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.

How do I import breakpoints in Visual Studio?

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.


2 Answers

Marvin's suggestion appears to be sufficient:

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

like image 108
sivano Avatar answered Oct 19 '22 05:10

sivano


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.

like image 28
RobinL Avatar answered Oct 19 '22 05:10

RobinL