views:

184

answers:

1

How to debug python programs in emacs?

I use python-mode.el

I get reference like import pdb; pdb.set_trace();

but not sure how to use it.

+2  A: 

Type M-x cd to change directory to the location of the program you wish to debug. Type M-x pdb. You'll be prompted with Run pdb (like this): pdb. Enter the name of the program (e.g. test.py).

At the (Pdb) prompt, type help to learn about how to use pdb.

Alternatively, you can put

import pdb 
pdb.set_trace()

right inside your program (e.g. test.py). Now type M-x shell to get a shell prompt. When you run your program, you'll be dumped into pdb at the point where pdb.set_trace() is executed.

unutbu
Using pdbtrack (through M-x shell) is probably a better solution. It's much easier to control directories and environments that way.
matt harrison
@matt with M-x pdb you can set break points in source files and a cursor will show the current position of execution as you step through: http://twistedmatrix.com/documents/current/core/howto/debug-with-emacs.html
Justin Smith