簡體   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