ipdb: IPython-enabled pdb
ipdb is an interactive debugger for Python that extends the functionality of the built-in `pdb` debugger. It integrates features from IPython, such as syntax highlighting, tab completion, better tracebacks, and an enhanced command set, making debugging more interactive and user-friendly. Currently at version 0.13.13, it maintains an active development pace with releases addressing compatibility and new features.
Warnings
- breaking Critical IPython dependency versioning: `ipdb` relies heavily on `IPython`. Ensure correct `IPython` versions are installed for your Python version to avoid conflicts or missing features. For Python 3.6, install `7.16.3 <= IPython < 7.17.0`. For Python > 3.6, install `IPython >= 7.31.1`. Consult `ipdb`'s `HISTORY.txt` for detailed historical requirements if using older Python versions.
- gotcha Do not leave `ipdb.set_trace()` calls in production code. These breakpoints will halt program execution and expose the interactive debugger, which is a security risk and an operational blocker.
- gotcha In Jupyter Notebooks on Windows, `ipdb` may occasionally fail to display the current line and context (e.g., with the 'l' command) due to inconsistent directory separator handling (mixed slashes).
- deprecated Older `ipdb` versions dropped support for various Python versions. `ipdb` version 0.6 dropped Python 2.4 support, version 0.8 dropped Python 2.5 support, and version 0.10.3 dropped Python 3.2 support. Current versions require Python >= 2.7, excluding 3.0-3.3.
- gotcha When using `ipdb` in environments that manipulate standard output (e.g., certain testing frameworks like older versions of `nose`), `ipdb`'s display might be affected. `ipdb` versions <= 0.9.4 had brittle strategies for handling such scenarios.
- gotcha Changes made to variables or objects within an IPython interactive shell launched from `ipdb` (e.g., using magic functions like `%ipdb`) might not always propagate back or affect the `ipdb` shell's context, leading to unexpected behavior if you expect state changes to persist across shells.
Install
-
pip install ipdb
Imports
- set_trace
import ipdb; ipdb.set_trace()
- pm
import ipdb; ipdb.pm()
- launch_ipdb_on_exception
from ipdb import launch_ipdb_on_exception
- iex
from ipdb import iex
Quickstart
import ipdb
def divide(a, b):
try:
# Set a breakpoint to inspect variables before the division
ipdb.set_trace()
result = a / b
return result
except ZeroDivisionError:
print("Cannot divide by zero!")
return None
print(divide(10, 2))
# To trigger the debugger on error, uncomment the line below and remove the try-except:
# divide(10, 0)