debugging 获取ipdb的IPython选项卡完成

zynd9foi  于 2023-03-08  发布在  Python
关注(0)|答案(6)|浏览(121)

我已经安装了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()的那一行。

irtuqstp

irtuqstp1#

我在Mac上使用Python 2.7.5 virtualenv中的ipython==0.13.2ipdb==0.7时也遇到了同样的现象。当我尝试调试时,我有内置的制表符完成功能,但没有当前作用域中的变量。我发现,我有一个自定义的.pdbrc位于我的主文件夹(http://docs.python.org/2/library/pdb.html#id2)中。在我注解掉所有内容后,制表符完成功能再次工作。
我不知道什么时候和为什么我添加了这个文件,但这是什么在那里:

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

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

x6yk4ghg

x6yk4ghg2#

我遇到了同样的问题,我修复了它:

sudo pip install --upgrade ipdb ipython readline

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

oknrviil

oknrviil3#

easy_install readline有帮助吗?

vc6uscn9

vc6uscn94#

我在ubuntu14.04上也遇到了同样的问题,并通过以下方式修复了它:
apt-get install libncurses5-dev
pip install --upgrade readline

4nkexdtk

4nkexdtk5#

截至2019年11月,几乎没有什么变化,所以下面是应该解决的问题:

pip install --upgrade ipdb gnureadline ptpython

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

axkjgtzd6#

试试这个:
1.创建一个文件:

vi ~/.ipython/profile_default/startup/00-first.py

1.并加上:

import logging

logging.getLogger('parso.cache').disabled=True
logging.getLogger('parso.cache.pickle').disabled=True
logging.getLogger().setLevel(logging.WARNING);
logging.getLogger('parso').setLevel(logging.WARNING)

相关问题