How to use the IPython debugger (ipdb)
This is a copy of Debugging with ipython and ipdb.
Debugging with ipython and ipdb
Make sure you have setuptools installed
- Try to run
- Should return something like: /usr/local/share/python/easy_install
Install ipython and ipdb
- sudo easy_install ipython
- sudo easy_install ipdb
- Windows installers can be found here:
- also install pyreadline: http://pypi.python.org/pypi/pyreadline/1.7.1
Place a breakpoint in your code
print 'Hello World!'
my_var = 10 / 3
import ipdb; ipdb.set_trace() # BREAKPOINT
Run your code
- ? for "help"
- ? s for "help for command s"
- l for "some more context"
- s for "step into"
- n for "step over"
- c for "continue to next breakpoint"
Sample program with a bug
- Download "buggy.py"
- Run the program:
- It should return the version of Django
- But it does not
- Place a breakpoint at line 45
- Step through it and fix it :)
Hint: Use pprint
- import pprint