2013-02-27 61 views
14

我已经安装了IPython(0.13.1)ipdb(0.7),我在行中插入了行import ipdb;ipdb.set_trace(),并运行了python my_script.py。现在我处于ipdb提示中,并且有一些自动完成(例如,一个裸标签),但它与我在输入IPython时获得的自动完成不同。在ipdb提示符requests.,然后<tab>(导入后)不会给我一个如IPython中的属性列表。如何通过ipdb获得与IPython中相同的选项卡完成?获得ipdb的IPython选项卡完成

顺便说一句,当我运行python -m ipdb my_script.py时,Tab完成的工作方式与IPython一样,但缺点是它从第一行开始调试器,而不是我放import ipdb;ipdb.set_trace()的行。

+2

这也发生在OS X上,通过ipip安装ipython和ipdb,并通过easy_install安装readline(全部在virtualenv中)。你使用的环境是什么,以便我们可以缩小这个范围? – Beau 2013-07-29 19:12:56

+1

我使用'Ubuntu 12.04',ipython和ipdb也通过pip安装。这个问题发生在虚拟环境之外以及虚拟环境之外。我得到Tab完成,但只有内置的函数/关键字(例如,当我在我的代码中创建'dic = {}'然后通过'ipdb; ipdb.set_trace()'进行调试并键入'di'时,按''tab'我只能看到'dict(','dir('和'divmod('。我看不到'dic')。 – Bentley4 2013-07-30 08:40:09

+0

这就是我所看到的 - 完成内置但不是本地或模块。 – Beau 2013-07-30 21:37:23

回答

3

请问easy_install readline有帮助吗?

+0

这个实际上在OSX中有所帮助 – 2015-10-24 00:01:02

6

我在我的Mac上使用ipython==0.13.2ipdb==0.7Python 2.7.5 virtualenv中有相同的现象。当我尝试进行调试时,我已经完成了内建的选项卡,但不是当前范围内的变量。我发现,我的自定义.pdbrc位于我的主文件夹(http://docs.python.org/2/library/pdb.html#id2)。在我评论完所有内容后,Tab完成工作再次开始。

我不知道什么时候,为什么我添加了这个文件,但是这是在那里:

# 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) 

还需要进一步研究,以检查什么打破了那里的制表完成...

+0

你让我的日子变好了。我的主文件夹! – 2015-04-29 22:11:09

1

我对Ubuntu的14.04同样的问题,得到它固定:

apt-get install libncurses5-dev

pip install --upgrade readline

+0

也适用于Ubuntu 16.04 \ o/ – 2017-06-02 17:51:42

2

我有同样的问题,我有固定它:

sudo pip install --upgrade ipdb ipython readline 

如果您还没有安装readline确保安装libncurses5-dev为@ musashi14建议做。

+0

在linux mint上完美工作18.2 – Bug 2017-08-16 22:49:21