Debugging python programs in emacs

Debugging python programs in emacs

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

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

Alternatively, you can put

import pdb 

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

For me, I needed to replace the default pdb with

python -m pdb

Debugging python programs in emacs

The realgud package (available from MELPA) supports PDB (among a gazillion other debuggers), and has a host of neat features that Emacs PDB doesnt have.

The one I like best is the shortkeys mode. Once you start debugging a program, you can press n, s, c etc. right in the source window, instead of having to type these commands in the PDB buffer. It also supports Visual-Studio style keybindings with function keys (f10, f11, f5, etc).

After installing RealGUD, you need to run M-x load-feature realgud to load it, and you can start pdb with M-x realgud:pdb.

Leave a Reply

Your email address will not be published. Required fields are marked *