Archive
pudb: a simple and intuitive debugger
Problem
You want to debug a Python source file. You have heard about pdb, but in the good old days you used Borland Pascal, Borland C, and you want something similar.
Solution
If you develop in the konsole, you must try pudb. “PuDB is a full-screen, console-based visual debugger for Python. Its goal is to provide all the niceties of modern GUI-based debuggers in a more lightweight and keyboard-friendly package. PuDB allows you to debug code right where you write and test it–in a terminal. If you’ve worked with the excellent (but nowadays ancient) DOS-based Turbo Pascal or C tools, PuDB’s UI might look familiar.” (source)

Links
- pudb HQ (@pypi)
- PuDB, a better Python debugger (Part 1)
- Hacking PuDB: Now an even better Python debugger (Part 2)
- Introduction to the PuDB Python Debugging Tool (by Prof. Norm Matloff )
For more alternatives, see this discussion about debugging (on reddit).
Usage tip
Add this line to your ~/.bashrc file:
alias pudb='python -m pudb'
Then you can start debugging with pudb like this:
$ pudb problem.py
Debugging in Python
If you are doing debugging with “print“, it’s time to try one of the following methods.
Debugging with pdb/ipdb
If you want a clear and gentle introduction to the usage of the Python debugger “pdb“, read Steve Ferg’s excellent tutorial Debugging in Python.
Here I make a short summary for reference purposes:
- “
import pdb” or “import ipdb as pdb“, then “pdb.set_trace()“ n(next)ENTER(repeat previous)q(quit)p<variable> (print value)c(continue)l(list where you are)s(step into subroutine)r(continue till the end of the subroutine)!<python command>
ipdb is like pdb but it adds syntax highlightning and completion. You can install it with “sudo pip install ipdb“. If you used pdb with “import pdb“, just change this line to “import ipdb as pdb“. This way the line “pdb.set_trace()” can be left unchanged.
Debugging with Winpdb
Another interesting debugger is Winpdb, which is a platform independent GUI debugger for Python with support for multiple threads, namespace modification, embedded debugging, encrypted communication… It can be installed from the Ubuntu repos (sudo apt-get install winpdb). Tutorial here.
Short summary again:
restart(restart debugging session)exitn(next)go(continue)x <python command>(exec, changes state)v <python command>(eval, print to console, no changes in state)j <line>(jump)s(step in subroutine)r(return from subroutine)bp <line>(breakpoint @ line)bp <line>, <expression>(conditional breakpoint @ line)bl(breakpoint list)bc <id> | *(breakpoint clear)
Debugging with the Eric IDE
I would sum up how to debug with the Eric IDE too:
- F5 (start debugging; untick “Don’t stop at first line” or set a breakpoint)
- F10 (stop)
- F7 (next, step in subroutines)
- F8 (next, step over subroutines)
- F9 (return, step out of subroutine)
- F6 (continue, go, run)
- Shift+F6 (continue till cursor)
- conditional breakpoints are supported (set a breakpoint, right click on it, edit)
I find Eric’s debugger is much faster than Winpdb.
Update (20141227)
If you want to add a break point to your script and you want to “break out” to ipython, then just add this line:
import ipdb; ipdb.set_trace()
