繁体   English   中英

获取 ipdb 的 IPython 选项卡完成

[英]Get IPython tab completion for ipdb

我安装了IPython(0.13.1)ipdb(0.7) ,我在脚本中插入了import ipdb;ipdb.set_trace()行并运行python my_script.py 现在我在 ipdb 提示符下,有一些自动完成(例如一个裸选项卡),但它与我进入 IPython 时得到的自动完成不同。 在 ipdb 提示requests. 然后<tab> (导入后)不会像在 IPython 中那样给我一个属性列表。 如何使用 ipdb 获得与 IPython 中相同的选项卡完成?

顺便说一句,当我运行python -m ipdb my_script.py ,选项卡完成就像在 IPython 中一样,但它的缺点是它从第一行而不是我放置的行开始调试器import ipdb;ipdb.set_trace()

我在我的 Mac 上使用ipython==0.13.2ipdb==0.7Python 2.7.5 virtualenv 中遇到了同样的现象。 当我尝试调试时,我对内置函数进行了选项卡补全,但对当前范围内的变量没有。 我发现,我的主文件夹 ( http://docs.python.org/2/library/pdb.html#id2 ) 中有一个自定义的.pdbrc 在我将所有内容注释掉后,选项卡完成再次起作用。

我不知道我何时以及为什么添加了这个文件,但这是里面的内容:

# See http://docs.python.org/2/library/pdb.html#id2 for the structure of this file.
import pdb

# 'inspect x' will print the source code for a method, class or function.
alias inspect import inspect;print inspect.getsource(%1)
alias i import inspect;print inspect.getsource(%1)
# 'help x' opens the man-style help viewer from the interpretter on an object
alias help !print help(%1)
alias h !print help(%1)
# For ordinary Python objects, ppo will pretty-print members and their values.
alias ppo pp %1.__dict__
# ppio runs ppo over a sequence of objects
alias ppio pp [a.__dict__ for a in %1]

# This tries to enable tab-completion of some identifiers.
!import rlcompleter
!pdb.Pdb.complete = rlcompleter.Completer(locals()).complete

# Taken from https://gist.github.com/1125049
# There are a couple of edge cases where you can lose terminal
# echo. This should restore it next time you open a pdb.
!import termios, sys
!termios_fd = sys.stdin.fileno()
!termios_echo = termios.tcgetattr(termios_fd)
!termios_echo[3] = termios_echo[3] | termios.ECHO
!termios_result = termios.tcsetattr(termios_fd, termios.TCSADRAIN, termios_echo)

需要进一步研究来检查是什么破坏了那里的制表符完成......

我遇到了同样的问题,我用以下方法修复了它:

sudo pip install --upgrade ipdb ipython readline

如果您没有安装readline ,请确保按照@musashi14 的建议安装libncurses5-dev

easy_install readline帮助吗?

我在 ubuntu 14.04 上遇到了同样的问题,并通过以下方式修复了它:

apt-get install libncurses5-dev

pip install --upgrade readline

截至2019-11 年,一些事情发生了变化,所以这里是应该解决的问题:

pip install --upgrade ipdb gnureadline ptpython

# Handly to enable ipdb on pytest exceptions
export PYTEST_ADDOPTS='--pdb --pdbcls=IPython.terminal.debugger:Pdb'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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