Hanan Shteingart Hanan Shteingart - 1 year ago 272
Python Question

How do I debug efficiently with spyder in Python?

I like Python and I like Spyder but I find debugging with Spyder terrible!

  • Every time I put a break point, I need to press two buttons: first
    the debug and then the continue button (it pauses at first line
    automatically) which is annoying.

  • Moreover, rather than having the standard iPython console with auto completion etc I have a lousy ipdb>> console which is just garbage.

  • The worst thing is that this console freezes very frequently even if I write prints or simple evaluation to try to figure out what is the bug. This is much worse than matlab.

  • Last but not least, if I call a function from within the
    ipdb>> console, and put a breakpoint in it, it will not stop there.
    It seems like I have to put the breakpoint there before I start the
    debugging (ctrl+F5).

Do you have a solution or maybe can you tell me how you debug python scripts and functions?

I am using fresh install of Anaconda on a Windows 8.1 64bit.

Answer Source

(Spyder dev here) We're aware the debugging experience in Spyder is far from ideal. What we offer right now is very similar to the standard Python debugger, but we're working to improve things in our next major version to provide something closer to what any scientist would expect of a debugger (in short, a regular IPython console that lets you inspect and plot variables at the current breakpoint).

Now about your points:

  1. It's true. We're thinking to improve that so that if the user press the Run button, and there is a breakpoint present in the current file, then Spyder enters in debug mode and executes the program until the first breakpoint is met.

  2. ipdb is the IPython debugger console. Unfortunately, due to limitations in the IPython architecture, it's very limited (no code completion and no history browsing with arrows). Furthermore, it's not possible to run arbitrary Python code in either ipdb or a regular pdb console. The commands you can run in ipdb are the ones you can read when evaluate the help command inside it.

  3. That's because, as I said, you can't evaluate arbitrary Python code.

  4. You need to put new breakpoints in our Editor so that they are synced with our Python/IPython consoles