PyCharm: how to do post mortem debugging in the ipython interactive console?
Given that you are using PyCharm, why not use the built-in debugger? There is ample documentation on how you can use it to set your own breakpoints, step through your stack, configure the debugger options etc.
Specifically for your use case, if you want to break on exceptions -- you can use Ctrl + Shift + F8 to open the breakpoints configuration screen. You can then check to break on Any exception for Python Exception Breakpoint. This would give you access to the exception and the entire stack (in the Frames section), context, variables etc. when something does happen.
It is possible in IPython to use the %pdb
magic.
Simply use %pdb
on IPython and whenever an error occurs you will be dropped in an ipdb
session with the Post Mortem of the error.
I don't really know if this works in PyCharm.
(I found this answer here some time ago)