Integration of IPython pdb

Overview

IPython pdb

https://travis-ci.org/gotcha/ipdb.png?branch=master https://codecov.io/gh/gotcha/ipdb/branch/master/graphs/badge.svg?style=flat

Use

ipdb exports functions to access the IPython debugger, which features tab completion, syntax highlighting, better tracebacks, better introspection with the same interface as the pdb module.

Example usage:

import ipdb
ipdb.set_trace()
ipdb.set_trace(context=5)  # will show five lines of code
                           # instead of the default three lines
                           # or you can set it via IPDB_CONTEXT_SIZE env variable
                           # or setup.cfg file
ipdb.pm()
ipdb.run('x[0] = 3')
result = ipdb.runcall(function, arg0, arg1, kwarg='foo')
result = ipdb.runeval('f(1,2) - 3')

Arguments for set_trace

The set_trace function accepts context which will show as many lines of code as defined, and cond, which accepts boolean values (such as abc == 17) and will start ipdb's interface whenever cond equals to True.

Using configuration file

It's possible to set up context using a .ipdb file on your home folder or setup.cfg on your project folder. You can also set your file location via env var $IPDB_CONFIG. Your environment variable has priority over the home configuration file, which in turn has priority over the setup config file. Currently, only context setting is available.

A valid setup.cfg is as follows

[ipdb]
context=5

A valid .ipdb is as follows

context=5

The post-mortem function, ipdb.pm(), is equivalent to the magic function %debug.

If you install ipdb with a tool which supports setuptools entry points, an ipdb script is made for you. You can use it to debug your python 2 scripts like

$ bin/ipdb mymodule.py

And for python 3

$ bin/ipdb3 mymodule.py

Alternatively with Python 2.7 only, you can also use

$ python -m ipdb mymodule.py

You can also enclose code with the with statement to launch ipdb if an exception is raised:

from ipdb import launch_ipdb_on_exception

with launch_ipdb_on_exception():
    [...]

Warning

Context managers were introduced in Python 2.5. Adding a context manager implies dropping Python 2.4 support. Use ipdb==0.6 with 2.4.

Warning

Using from future import print_function for Python 3 compat implies dropping Python 2.5 support. Use ipdb<=0.8 with 2.5.

Issues with stdout

Some tools, like nose fiddle with stdout.

Until ipdb==0.9.4, we tried to guess when we should also fiddle with stdout to support those tools. However, all strategies tried until 0.9.4 have proven brittle.

If you use nose or another tool that fiddles with stdout, you should explicitly ask for stdout fiddling by using ipdb like this

import ipdb
ipdb.sset_trace()
ipdb.spm()

from ipdb import slaunch_ipdb_on_exception
with slaunch_ipdb_on_exception():
    [...]

Development

ipdb source code and tracker are at https://github.com/gotcha/ipdb.

Pull requests should take care of updating the changelog HISTORY.txt.

Manual testing

To test your changes, make use of manual_test.py. Create a virtual environment, install IPython and run python manual_test.py and check if your changes are in effect. If possible, create automated tests for better behaviour control.

Third-party support

Products.PDBDebugMode

Zope2 Products.PDBDebugMode uses ipdb, if available, in place of pdb.

iw.debug

iw.debug allows you to trigger an ipdb debugger on any published object of a Zope2 application.

ipdbplugin

ipdbplugin is a nose test runner plugin that also uses the IPython debugger instead of pdb. (It does not depend on ipdb anymore).

Comments
  • Relicense as PSF-compatible?

    Relicense as PSF-compatible?

    I was hoping to contribute to this module, but as both Python itself and IPython are permissively licensed, it might make sense for this to also be permissively licensed. If not, I'll eventually make something MIT licensed from scratch that meets my needs.

    opened by wesm 40
  • ipdb should ask iPython 5 which debugger class to use

    ipdb should ask iPython 5 which debugger class to use

    I've got this in two ways:

    1. Inside honcho, if I'm using an import ipdb; ipdb.sset_trace() in my Django app
    2. Same idea, but inside nose tests for the Django app

    Although a breakpoint in the running app did happen, we had some weird behaviour with the autocompletion that used to be there in 4.2 but didn't seem to be present once we bumped ipython to 5, maybe that was known.

    Here's the traceback for my test

        my_project.py line 77 in my_function
          import ipdb; ipdb.sset_trace()
        /data/virtualenv/my_project/lib/python2.7/site-packages/ipdb/stdout.py line 18 in sset_trace
          set_trace(frame, context)
        /data/virtualenv/my_project/lib/python2.7/site-packages/ipdb/__main__.py line 93 in set_trace
          p = _init_pdb(context).set_trace(frame)
        /data/virtualenv/my_project/lib/python2.7/site-packages/ipdb/__main__.py line 76 in _init_pdb
          p = Pdb(def_colors)
        /data/virtualenv/my_project/lib/python2.7/site-packages/IPython/terminal/debugger.py line 15 in __init__
          self.pt_init()
        /data/virtualenv/my_project/lib/python2.7/site-packages/IPython/terminal/debugger.py line 38 in pt_init
          self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
       AttributeError: 'TerminalInteractiveShell' object has no attribute '_eventloop'
    
    Reproducable Bug Work in Progress 
    opened by JBKahn 22
  • Starting ipdb inside ipython breaks color coding (windows)

    Starting ipdb inside ipython breaks color coding (windows)

    Scenario:

    1. Run ipython (in windows), import and run a method that includes a call to ipdb (i just included import ipdb; ipdb.set_trace() inside a method that i imported in this case django's makemessages.py)
    2. Debugger starts but all the color coding is output as raw strings, like so:
    > ←[1;32mc:\users\big\envs\appricot\lib\site-packages\django\core\management\commands\makemessages.py←[0m(184)←[0;36mprocess_file←
    [1;34m()←[0m
    ←[1;32m    183 ←[1;33m        ←[1;32mimport←[0m ←[0mipdb←[0m←[1;33m;←[0m ←[0mipdb←[0m←[1;33m.←[0m←[0mset_trace←[0m←[1;33m(←[0m←[1;
    33m)←[0m←[1;33m←[0m←[0m
    ←[0m←[1;32m--> 184 ←[1;33m        ←[0mthefile←[0m ←[1;33m=←[0m ←[0mfile←[0m←[1;33m←[0m←[0m
    ←[0m←[1;32m    185 ←[1;33m        ←[0morig_file←[0m ←[1;33m=←[0m ←[0mos←[0m←[1;33m.←[0m←[0mpath←[0m←[1;33m.←[0m←[0mjoin←[0m←[1;33m
    (←[0m←[0mdirpath←[0m←[1;33m,←[0m ←[0mfile←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
    ←[0m
    ipdb>
    

    Edit: Just to clarify, my issue is reproducible on the first ipdb run, just by entering ipython and importing any module (sample.py) which includes the line import ipdb;ipdb.set_trace()

    Released 
    opened by asfaltboy 21
  • quit does not abort

    quit does not abort

    I hope I'm not the only one with this problem, but since I've upgraded to IPython 5, it is impossible to quit from a ipdb session, as before.

    Here is a sample script:

    def main():
        print('hello')
        while True:
            import ipdb; ipdb.set_trace()
            print('loop')
    
    if __name__ == '__main__':
        main()
    

    And a sample run:

    python3 mwe.py
    hello
    > /home/dojeda/temp/mwe.py(5)main()
          3     while True:
          4         import ipdb; ipdb.set_trace()
    ----> 5         print('loop')
          6 
          7 if __name__ == '__main__':
    
    ipdb> c
    loop
    > /home/dojeda/temp/mwe.py(4)main()
          2     print('hello')
          3     while True:
    ----> 4         import ipdb; ipdb.set_trace()
          5         print('loop')
          6 
    
    ipdb> q
    loop
    > /home/dojeda/temp/mwe.py(5)main()
          3     while True:
          4         import ipdb; ipdb.set_trace()
    ----> 5         print('loop')
          6 
          7 if __name__ == '__main__':
    
    ipdb> quit()
    loop
    > /home/dojeda/temp/mwe.py(4)main()
          2     print('hello')
          3     while True:
    ----> 4         import ipdb; ipdb.set_trace()
          5         print('loop')
          6 
    
    ipdb> !!q
    loop
    > /home/dojeda/temp/mwe.py(5)main()
          3     while True:
          4         import ipdb; ipdb.set_trace()
    ----> 5         print('loop')
          6 
          7 if __name__ == '__main__':
    
    ipdb> import sys; sys.exit(0)
    *** SystemExit: 0
    ipdb>
    

    Version information: ipdb==0.10.1 ipython==5.1.0

    IPython issue Waiting for upstream fix 
    opened by dojeda 19
  • Stop setting deprecated color_scheme argument.

    Stop setting deprecated color_scheme argument.

    Fixes #144.

    The deprecation warning is particularly annoying in my development setup where warnings are treated as failures during tests.

    Since IPython 5.1.0, shell.colors is the value used for color_scheme anyway. See https://github.com/ipython/ipython/blob/5.1.0/IPython/core/debugger.py#L240.

    ipdb still supports IPython 5.0 so it may make sense to either bump that dependency to 5.1 or add additional code to keep compatibility with IPython 5.0. I'm not sure which approach you prefer.

    opened by bmw 17
  • Newer IPython compability

    Newer IPython compability

    Hi,

    This patch makes ipdb more resilient to different versions of IPython as embed module was moved from IPython.frontend.terminal.embed to IPython.terminal.embed in latest IPython versions. I believe ipdb in pip is taken from your repository, so would be great to have this fix there.

    Cheers,

    Piotr

    opened by pgularski 14
  • ipdb throws error when using a MultiIndex in pandas and python 3.10

    ipdb throws error when using a MultiIndex in pandas and python 3.10

    I've stumbled upon an issue while using Spyder with pandas and python 3.10. Whenever the ipdb debugger hits a line where a MultiIndex is set, the following error is thrown:

    AttributeError: 'MultiIndex' object has no attribute 'offsets'
    

    This issue was already encountered by someone else, they reported it at pandas: https://github.com/pandas-dev/pandas/issues/46890 As the issue only occurred in Spyder I opened an issue there: https://github.com/spyder-ide/spyder/issues/17821 It was closed in favour of the pandas issue.

    In the pandas issue a commenter reproduced the error and showed that this only happens with ipdb and not pdb or regular python.

    As this issue is seemingly only occurring with the combination ipdb + pandas + python=3.10 I am opening an issue here.

    In case a conda environment is needed to reproduce the issue, you can check this comment.

    opened by ba-tno 13
  • ipdb `with launch_ipdb_on_exception():` gives pylint E1129 error mesage

    ipdb `with launch_ipdb_on_exception():` gives pylint E1129 error mesage

    I am using: ipdb==0.13.9


    For the code-block from answer for Launch an IPython shell on exception

    from ipdb import launch_ipdb_on_exception
    
    with launch_ipdb_on_exception():
        main()
    

    I am getting following warning message: [not-context-manager] Context manager 'generator' doesn't implement __enter__ and __exit__. [E1129]

    How could I prevent this warning message?

    opened by avatar-lavventura 13
  • ipython 7.10.1 and ipdb 0.12.3

    ipython 7.10.1 and ipdb 0.12.3

    I'm currently running into an issue with inputhook

    In [1]: import ipdb; ipdb.set_trace()
    <IPython.terminal.debugger.TerminalPdb object at 0x7fbca4678b50>
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-1-f3f8e0a2fcd8> in <module>
    ----> 1 import ipdb; ipdb.set_trace()
    
    /usr/local/lib/python3.8/site-packages/ipdb/__main__.py in set_trace(frame, context)
         65     if frame is None:
         66         frame = sys._getframe().f_back
    ---> 67     p = _init_pdb(context).set_trace(frame)
         68     if p and hasattr(p, 'shell'):
         69         p.shell.restore_sys_module_state()
    
    /usr/local/lib/python3.8/site-packages/ipdb/__main__.py in _init_pdb(context, commands)
         46 def _init_pdb(context=3, commands=[]):
         47     try:
    ---> 48         p = debugger_cls(context=context)
         49     except TypeError:
         50         p = debugger_cls()
    
    /usr/local/lib/python3.8/site-packages/IPython/terminal/debugger.py in __init__(self, *args, **kwargs)
         28         Pdb.__init__(self, *args, **kwargs)
         29         self._ptcomp = None
    ---> 30         self.pt_init()
         31
         32     def pt_init(self):
    
    /usr/local/lib/python3.8/site-packages/IPython/terminal/debugger.py in pt_init(self)
         68         if not PTK3:
         69             print(self)
    ---> 70             options['inputhook'] = self.inputhook
         71         self.pt_app = PromptSession(**options)
         72
    
    AttributeError: 'TerminalPdb' object has no attribute 'inputhook'
    

    I'm trying to investigate and I'll update with my own findings

    opened by JBKahn 12
  • Errors importing ipdb

    Errors importing ipdb

    I cannot seem to be able to import ipdb when using ipython notebook. I can import ipdb in all other instances (i.e. ipython terminal or python terminal).

    I am using jupyter 4.0.6 and ipython (4.1.1).

    When I import ipdb using ipython/jupyter, I receive the following error:

    `--------------------------------------------------------------------------- MultipleInstanceError Traceback (most recent call last) in () 1 import sys 2 print(sys.version) ----> 3 import ipdb

    /usr/local/lib/python3.4/dist-packages/ipdb/init.py in () 14 # You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. 15 ---> 16 from ipdb.main import set_trace, post_mortem, pm, run, runcall, runeval, launch_ipdb_on_exception 17 18 pm # please pyflakes

    /usr/local/lib/python3.4/dist-packages/ipdb/main.py in () 71 # the instance method will create a new one without loading the config. 72 # i.e: if we are in an embed instance we do not want to load the config. ---> 73 ipapp = TerminalIPythonApp.instance() 74 shell = get_ipython() 75 def_colors = shell.colors

    /usr/local/lib/python3.4/dist-packages/traitlets/config/configurable.py in instance(cls, _args, *_kwargs) 413 raise MultipleInstanceError( 414 'Multiple incompatible subclass instances of ' --> 415 '%s are being created.' % cls.name 416 ) 417

    MultipleInstanceError: Multiple incompatible subclass instances of TerminalIPythonApp are being created.`

    Bug 
    opened by cchrysostomou 12
  • History across different ipdb sessions?

    History across different ipdb sessions?

    Is it possible to save history across different ipdb sessions? I would like pull up commands from my previous ipdb debug session that was invoked using ipdb.set_trace().

    Feature request 
    opened by phani-vadrevu 12
  • TAB completion not working when fiddling with stdout

    TAB completion not working when fiddling with stdout

    Hey, Thanks for the information on the README about using ipdb when fiddling with stdout! That has solved a headache I've had for quite a while, whilst working within a forked repo which fiddles with stdout for logging purposes. I'm now able to use ipdb by running: import ipdb; ipdb.sset_trace(); ipdb.spm() The arrow keys work correctly now, which they didn't before. However, TAB completion still doesnt work for me in this scenario. When I hit TAB, the cursor moves forward. When I'm not fiddling with stdout, TAB completion works correctly for me.

    Any ideas how I could solve this? In case it's helpful, the code which is fiddling with stdout is here:

    Question 
    opened by ebartrum 1
  • List comprehension problem

    List comprehension problem

    While using IPython import embed; embed() in an ipdb session list comprehensions seem to have a broken scope, take the snippet as an example. Confirmed this is not an IPython issue. image (41)

    opened by zwedwin 4
  • manual set ipdb shell to vi mode work in linux but escape char wrong in windows

    manual set ipdb shell to vi mode work in linux but escape char wrong in windows

    i add one line in ipdb main.py _get_debugger_cls to use command vi mode when debug ipdb.set_trace, and this work good in linux

    def _get_debugger_cls():
        shell = get_ipython()
        #shell=None
        if shell is None:
            # Not inside IPython
            # Build a terminal app in order to force ipython to load the
            # configuration
            ipapp = TerminalIPythonApp()
            # Avoid output (banner, prints)
            ipapp.interact = False
            ipapp.initialize(["--no-term-title"])
            shell = ipapp.shell
    
    
    ######################add line
            shell.editing_mode='vi'
        else:
    
    

    but when i do same thing in windows , vi mode prompt broke, and print some char like ?[6 qipdb> list?[2 q?[2 ?[2 q it look like some cursor control escape char i think.... and this both happen in cmd and powershell , but when create cmd in ConEmu , ipdb vi mode work great is there some config i set wrong ? or other nomal way to config vi mode in ipdb?

    Question 
    opened by WillDawnlll 1
  • Question: adding my own command to ipdb while in breakpoint()

    Question: adding my own command to ipdb while in breakpoint()

    Hi,

    I searched and tried different things, but I can't have my own command (which I put as a def foo() in a .py file under ~\.ipython\profile_default\startup ) visible when debugging a breakpoint().

    The command is visible at the ipython interactive shell but not under breakpoint().

    Thanks!!

    Question 
    opened by gilbh 0
  • tab completion for the expression after “p”/“pp” command

    tab completion for the expression after “p”/“pp” command

    In pdb, when I type p foo before hitting Tab, it finds all variables in scope with prefix foo, like foobar. In ipdb it shows wrong completion (magic functions). This feature is useful because I’m used to print variables with p/pp command (to avoid collision between variables and commands).

    opened by FranklinYu 6
Owner
Godefroid Chapelle
Godefroid Chapelle
pdb++, a drop-in replacement for pdb (the Python debugger)

pdb++, a drop-in replacement for pdb What is it? This module is an extension of the pdb module of the standard library. It is meant to be fully compat

null 1k Jan 2, 2023
pdb++, a drop-in replacement for pdb (the Python debugger)

pdb++, a drop-in replacement for pdb What is it? This module is an extension of the pdb module of the standard library. It is meant to be fully compat

null 1k Dec 24, 2022
pdb++, a drop-in replacement for pdb (the Python debugger)

pdb++, a drop-in replacement for pdb What is it? This module is an extension of the pdb module of the standard library. It is meant to be fully compat

null 1k Jan 2, 2023
Python code snippets for extracting PDB codes from .fasta files

Python_snippets_for_bioinformatics Python code snippets for extracting PDB codes from .fasta files If you have a single .fasta file for all protein se

Sofi-Mukhtar 3 Feb 9, 2022
A Python script to download PDB files associated with a Portable Executable (PE)

A Python script to download PDB files associated with a Portable Executable (PE)

Podalirius 33 Jan 3, 2023
allow windows programs to call dssp/mkdssp command from wsl; rework biopython on windows (PDB -> dssp -> fasta)

dssp-wsl Converting PDB (Protein Data Bank) file format to DSSP file format is required for generating datasets of peptides and their secondary struct

Taine Zhao 1 Feb 23, 2022
Plotting library for IPython/Jupyter notebooks

bqplot 2-D plotting library for Project Jupyter Introduction bqplot is a 2-D visualization system for Jupyter, based on the constructs of the Grammar

null 3.4k Dec 29, 2022
Plotting library for IPython/Jupyter notebooks

bqplot 2-D plotting library for Project Jupyter Introduction bqplot is a 2-D visualization system for Jupyter, based on the constructs of the Grammar

null 3.4k Dec 30, 2022
IPython/Jupyter notebook module for Vega and Vega-Lite

IPython Vega IPython/Jupyter notebook module for Vega 5, and Vega-Lite 4. Notebooks with embedded visualizations can be viewed on GitHub and nbviewer.

Vega 335 Nov 29, 2022
Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js

pivottablejs: the Python module Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js Installation pip install pivot

Nicolas Kruchten 512 Dec 26, 2022
Plotting library for IPython/Jupyter notebooks

bqplot 2-D plotting library for Project Jupyter Introduction bqplot is a 2-D visualization system for Jupyter, based on the constructs of the Grammar

null 3k Feb 18, 2021
IPython/Jupyter notebook module for Vega and Vega-Lite

IPython Vega IPython/Jupyter notebook module for Vega 5, and Vega-Lite 4. Notebooks with embedded visualizations can be viewed on GitHub and nbviewer.

Vega 294 Feb 12, 2021
Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js

pivottablejs: the Python module Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js Installation pip install pivot

Nicolas Kruchten 419 Feb 11, 2021
jupyter/ipython experiment containers for GPU and general RAM re-use

ipyexperiments jupyter/ipython experiment containers and utils for profiling and reclaiming GPU and general RAM, and detecting memory leaks. About Thi

Stas Bekman 153 Dec 7, 2022
IPython: Productive Interactive Computing

IPython: Productive Interactive Computing Overview Welcome to IPython. Our full documentation is available on ipython.readthedocs.io and contains info

IPython 15.6k Dec 31, 2022
Seamlessly run Python code in IPython from Vim

Seamlessly run Python code from Vim in IPython, including executing individual code cells similar to Jupyter notebooks and MATLAB. This plugin also supports other languages and REPLs such as Julia.

Hans Chen 269 Dec 20, 2022
An IPython Notebook tutorial on deep learning for natural language processing, including structure prediction.

Table of Contents: Introduction to Torch's Tensor Library Computation Graphs and Automatic Differentiation Deep Learning Building Blocks: Affine maps,

Robert 1.8k Jan 4, 2023
A slightly opinionated template for iPython configuration for interactive development

A slightly opinionated template for iPython configuration for interactive development. Auto-reload and no imports for packages and modules in the project.

Seva Zhidkov 24 Feb 16, 2022
Pandas on AWS - Easy integration with Athena, Glue, Redshift, Timestream, QuickSight, Chime, CloudWatchLogs, DynamoDB, EMR, SecretManager, PostgreSQL, MySQL, SQLServer and S3 (Parquet, CSV, JSON and EXCEL).

AWS Data Wrangler Pandas on AWS Easy integration with Athena, Glue, Redshift, Timestream, QuickSight, Chime, CloudWatchLogs, DynamoDB, EMR, SecretMana

Amazon Web Services - Labs 3.3k Jan 4, 2023