在 emacs 中调试 python 程序
如何在 emacs 中调试 python 程序?我正在使用 python-mode.el
我发现参考文献建议:
import pdb; pdb.set_trace();
但我不确定如何使用它。
How do I debug python programs in emacs? I'm using python-mode.el
I've found references suggesting:
import pdb; pdb.set_trace();
but I'm not sure how to use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
realgud
包(可从 MELPA 获得)支持 PDB(以及无数其他调试器),并且具有许多 Emac 的 PDB 所没有的简洁功能。我最喜欢的是快捷键模式。一旦开始调试程序,您可以直接在源代码窗口中按
n
、s
、c
等,而不必键入这些PDB 缓冲区中的命令。它还支持带有功能键的 Visual-Studio 样式键绑定(f10
、f11
、f5
等)。安装RealGUD后,需要运行
Mx load-feature realgud
来加载它,并且可以使用Mx realgud:pdb
启动pdb
。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
M-x load-feature realgud
to load it, and you can startpdb
withM-x realgud:pdb
.输入
Mx cd
将目录更改为您要调试的程序的位置。输入
Mx pdb
。系统将提示您运行 pdb(如下所示):pdb
。输入程序的名称(例如test.py
)。在
(Pdb)
提示符下,键入help
以了解如何使用 pdb。或者,您可以
直接放在程序中(例如
test.py
)。现在输入Mx shell
以获取 shell 提示符。当您运行程序时,您将在执行pdb.set_trace()
时转储到pdb
中。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 withRun pdb (like this): pdb
. Enter the name of the program (e.g.test.py
).At the
(Pdb)
prompt, typehelp
to learn about how to use pdb.Alternatively, you can put
right inside your program (e.g.
test.py
). Now typeM-x shell
to get a shell prompt. When you run your program, you'll be dumped intopdb
at the point wherepdb.set_trace()
is executed.对我来说,我需要将默认的“pdb”替换为
For me, I needed to replace the default "pdb" with