Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug python in visual studio (how to step in a library)?

I'm writing python in visual studio 2015. I want to ask how to step into a library if I'm using a function that is defined in the library.

For example, I wrote the following code,

import numpy as np
from sklearn import linear_model, datasets
np.random.seed(0)
regdata = datasets.make_regression(100, 1, noise = 20.0)

And I want to step into the makeregression() function at 4th line (this function is defined in samples_generator.py, scikit-learn package) to see what is happening inside of the function. When I press F11(shortcut for step into) in visual studio, instead of moving into samples_generator.py, the arrow just moves to next line of my code.

Is there a way to let me step into a function which is defined in a library? Appreciate your help.

like image 758
Ema Avatar asked Dec 03 '15 02:12

Ema


People also ask

How do I debug a Python code in Visual Studio?

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 you debug in Python step by step?

Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().

How do I step through Python in Visual Studio?

To continue running the program until the next breakpoint is reached, use Continue (F5). Because you have a breakpoint in the for loop, you break on the next iteration. Stepping through hundreds of iterations of a loop can be tedious, so Visual Studio lets you add a condition to a breakpoint.

How do you debug step by step in visual code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


1 Answers

Did you try to use the option "Enable debugging of the Python standard library" in Python Tools:

Python Tools

To get here, open Tools->Options->Python Tools->Debugging in Visual Studio.

like image 124
Geir Ivar Jerstad Avatar answered Oct 06 '22 19:10

Geir Ivar Jerstad