简体   繁体   中英

Get IPython tab completion for ipdb

I have IPython(0.13.1) and ipdb(0.7) installed, I inserted the line import ipdb;ipdb.set_trace() in my script and ran python my_script.py . Now I am in the ipdb prompt and there is some autocompletion (eg a bare tab) but it's not the same as the autocompletion I get when I enter IPython. In the ipdb prompt requests. then <tab> (after import) does not give me a list of attributes as in IPython. How do I get that same tab completion as in IPython with ipdb?

Btw, when I run python -m ipdb my_script.py the tab completion works just as in IPython but the downside of this is that it starts the debugger from the first line instead of the line I've put import ipdb;ipdb.set_trace() .

I had the same phenomenon on my Mac using ipython==0.13.2 and ipdb==0.7 inside a Python 2.7.5 virtualenv. When I tried to debug, I had the tab completion for the builtins, but not for the variables in the current scope. I discovered, that I had a custom .pdbrc located in my home folder ( http://docs.python.org/2/library/pdb.html#id2 ). After I commented all the stuff out, the tab completion worked again.

I don't know when and why I added this file, but this is what was in there:

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

Further research is needed to check what breaks the tab-completion in there...

I had the same problem and I fixed it with:

sudo pip install --upgrade ipdb ipython readline

If you don't have readline installed make sure to install libncurses5-dev as @musashi14 suggested.

easy_install readline帮助吗?

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

apt-get install libncurses5-dev

pip install --upgrade readline

As of 2019-11 few things changes so here is what should fix it:

pip install --upgrade ipdb gnureadline ptpython

# Handly to enable ipdb on pytest exceptions
export PYTEST_ADDOPTS='--pdb --pdbcls=IPython.terminal.debugger: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