Python Debugger (pdb) is easy to use, simply put
breakpoint() in your
.py file and run it (python >= 3.7).
Florian Preinstorfer made a great cheatsheet for what to do once you’re inside the debugger.
If you want to enter the regular python REPL from the debug mode type
The vanilla python debugger is good, but it misses some basic features such as tab completion. Luckily there is ipdb which is a (near) drop-in replacement.
To set it up:
- In your python environment: install ipdb
python -m pip install ipdb
- In your shell’s rc file: set python breakpoint to ipdb
export PYTHONBREAKPOINT = ipdb.set_trace
- In your root folder: Create a
.pdbrcwith this content (credits to Nina Zahrenko):
# Install IPython: python3 -m pip install ipython import IPython from traitlets.config import get_config cfg = get_config() cfg.InteractiveShellEmbed.colors = "Linux" # syntax highlighting cfg.InteractiveShellEmbed.confirm_exit = False alias interacti IPython.embed(config=cfg) # I replaced `interacti` with `ii`
In Jupyter Notebooks#
In jupyter notebooks you can start the debugger as above, but you can also use the
It works like this:
- Get an error in a cell
%debugin another cell to start the debugger the error point of last run cell