debugging python script in ipython

本文介绍如何解决ipython不支持内置pdb调试器的问题,并提供了使用pydb进行调试的步骤。包括安装pydb、设置环境变量以及启动调试会话等关键操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ipython doesn't work with built-in pdb debugger. While I tried to debug a python script with " run -d script.py" within ipython shell, I got bellow error:
AttributeError: Pdb instance has no attribute 'curframe'

To debug script in ipython, we need to use a different debugger, pydb, for example. There are only three steps to setup and use it.
  1. download and install pydb.
  2. start ipython with -pydb argument: ipython -pydb
  3. start debugging with: run -d script.py
It's mandatory to set HOME environment variable to use pydb. On my windows box, there is no HOME environment variable set by default, and I got bellow error:
KeyError: 'HOME'
It can be solved by adding HOME environment variable.

Because pydb use the same set of commands with gdb, it's fairly straightforward to get start with it if you have done some debugging in gdb. This is one reason why I pick it as my debugger.

Reference:
Introducing the pydb Debugger
Debugging in Python
Traceback (most recent call last): File "E:\Python\Scripts\spyder-script.py", line 10, in sys.exit(main()) ^^^^^^ File "E:\Python\Lib\site-packages\spyder\app\start.py", line 286, in main mainwindow.main(options, args) File "E:\Python\Lib\site-packages\spyder\app\mainwindow.py", line 1419, in main mainwindow = create_window(MainWindow, app, splash, options, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Python\Lib\site-packages\spyder\app\utils.py", line 360, in create_window main.setup() File "E:\Python\Lib\site-packages\spyder\app\mainwindow.py", line 677, in setup internal_plugins = find_internal_plugins() ^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Python\Lib\site-packages\spyder\app\find_plugins.py", line 45, in find_internal_plugins mod = importlib.import_module(entry_point.module) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Python\Lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1204, in _gcd_import File "", line 1176, in _find_and_load File "", line 1147, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "E:\Python\Lib\site-packages\spyder\plugins\debugger\plugin.py", line 35, in from spyder.plugins.ipythonconsole.widgets.run_conf import IPythonConfigOptions File "E:\Python\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\__init__.py", line 15, in from .debugging import DebuggingWidget File "E:\Python\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\debugging.py", line 18, in from IPython.core.history import HistoryManager File "E:\Python\Lib\site-packages\IPython\core\history.py", line 16, in from IPython.utils.decorators import undoc File "E:\Python\Lib\site-packages\IPython\__init__.py", line 54, in from .core.application import Application File "E:\Python\Lib\site-packages\IPython\core
04-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值