Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the green "Attach Debugger" button in Python console using PyCharm

I was wondering how to use this green bug button on the left side of Python console. I've been searched official documents but there seems to be no description of this button. Note I am asking the button on the left side, not the button on the right top corner.

I'm using IPython console and found %debug magic is not available anymore. I'd like to know what's the usage of that button and how to use %debug magic in IPython console.

enter image description here

like image 380
spacegoing Avatar asked Sep 24 '16 03:09

spacegoing


People also ask

How do I use the debugging tool in PyCharm?

By default, the Debug tool window opens when your program hits a breakpoint and is not hidden when the session is terminated. To change this behavior, clear the Show debug window on breakpoint checkbox on the Build, Execution, Deployment | Debugger page of the IDE settings Ctrl+Alt+S .

How do I use Python console in PyCharm?

You can assign a shortcut to open Python console: press Ctrl+Alt+S , navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console. The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.

How do you Debug a Python console?

To make use of the module as a method for debugging, you can use the interact() function of the module, which stops execution of the program at the point at which it is called, and provides you with an interactive console so that you can examine the current state of your program.


Video Answer


1 Answers

I found your question while searching for the answer myself; eventually I hit upon this video that shows it in use: https://www.youtube.com/watch?v=JcOCNgXXhmE

Basically, you have to set a breakpoint in a file you're editing, import the file in the console, click the "Attach Debugger" button and then run code that hits the breakpoint -- at that point, the debugger tool will open and you can step through it.

It's not exactly what I was hoping for -- I was hoping to attach the debugger and then step through a statement I'd just typed, as one can with IPython's %debug <statement> (which still works, but does not provide the visual niceties).

The best solution I've found for that is to use a scratch file, type the statement I want to step through, then run the debugger with that.

like image 167
Wil Cooley Avatar answered Oct 21 '22 10:10

Wil Cooley