Debugging in Python

Posted by Bruce Liu on March 8, 2021 , updated on August 5, 2022

🏷️ Tags: Python , pdb , pudb

pdb - the Python Debugger

  • Invoke pbd from terminal to debug the entire script.

    python -m pdb
  • Insert import pdb; pdb.set_trace() in a specific line of the script.

  • Insert breakpoint() in the script. The built-in breakpoint() is a equivalent way of import pdb; pdb.set_trace().

  • Commands: c(ontinue), s(tep), n(ext), r(eturn), j(ump), q(uit) .. more.

PuDB - a console-based visual debugger for Python


Install PuDB by pip install pudb or conda install -c conda-forge pudb.


Similar to pdb,

  • Debug the entire script with:



    python -m pudb
  • Insert in a specific line with:

    from pudb import set_trace; set_trace()


    import pudb; pu.db
  • Integrate pudb with breakpoint() function. Add:

    export PYTHONBREAKPOINT="pudb.set_trace"

    in your .bashrc or .zshrc. Then use breakpoint() in your script.

  • Commands: tyep ‘?’ in the console to check the conmand list.


Python tools

Share on:

« PREVIOUS: Calculator for loan and repay
NEXT: Academic journals on climate change »