Search code examples
pythondebuggingconsoleinteractive

In Python, how do I debug with an interactive command line (and visual breakpoints?)


I've recently moved from Matlab to Python. Python is a much better language (from the point of view of a computer scientist), but Python IDEs all seem to lack one important thing:

A proper interactive debugger.

I'm looking for:

  • The ability to set breakpoints graphically by clicking next to a line of code in the editor.

  • The ability to run ANY CODE while stopped in the debugger, including calling functions from my code, showing new windows, playing audio, etc.

  • When an error occurs, the debugger should automatically open an interactive console at the error line.

  • Once done with the interactive console, you can resume normal execution.

Matlab has all these features and they work incredibly well, but I can't find them anywhere in Python tools.

I've tried:

  • PyCharm: the interactive console is clunky, often fails to appear, and crashes all the time (I've tried several different versions and OSs).

  • IPython: can't set breakpoints -Launching a Python console programatically: you have to stop your code, insert an extra line of code, and run again from the beginning to do this. Plus, you can't access functions already imported without re-importing them.

Being able to debug and fix problems THE FIRST TIME THEY APPEAR is very important to me, as I work in programs that often take dozens of minutes to re-run (computational neuroscience).

CONCLUSION: there is NO way to do all of these in Python at the moment. Let us hope that PyLab development accelerates.


Solution

  • You can do all this in the iPython Notebook. Use the magic command %pdb to stop on error.