Skip to main content

Debugging Python

Here are some options for how to inspect and debug Python code:

print

Add print statements to your code and rerun your program to view the output:

print('any', values, you_want, 'to see')

Python REPL

Instead of running your whole program, start a Python REPL session, and import and run just the portions of your code you want to inspect:

$ python
$ from my_module import my_function
$ my_function()

pdb

See my Pdb notes.

ipdb

# use ipdb instead of pdb
$ PYTHONBREAKPOINT=ipdb.set_trace python file.py

pudb

# use pudb instead of pdb
$ PYTHONBREAKPOINT=pudb.set_trace python file.py

pdbpp

 

ipython

 

jupyter

See my Jupyter notes.

VS Code debugger

 

Research 📚

Inbox

  • Online Python Tutor • Online Compiler and Visual Debugger for Python, Java, C, C++, and JavaScript 🛠️
  • snoop • A powerful set of Python debugging tools, based on PySnooper 🛠️
  • birdseye • Graphical Python debugger which lets you easily view the values of all evaluated expressions 🛠️
  • Python Debugging (PyCharm + VS Code) - How to use the PyCharm and VS Code debuggers, and how to use breakpoints and conditional breakpoints to track down where problems are coming from - mCoding