简体   繁体   中英

Debugging python programs in emacs

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.

Type Mx cd to change directory to the location of the program you wish to debug. Type Mx pdb . You'll be prompted with Run pdb (like this): pdb . Enter the name of the program (eg 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 (eg test.py ). Now type Mx 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.

对我来说,我需要替换默认的“pdb”

python -m pdb myscript.py

The realgud package (available from MELPA) supports PDB (among a gazillion other debuggers), and has a host of neat features that Emac's PDB doesn't 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 Mx load-feature realgud to load it, and you can start pdb with Mx realgud:pdb .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM