Skip to content

Using a GUI Python Debugger with Sage (PUDB)

Maxie D. Schmidt edited this page Dec 9, 2016 · 2 revisions

Introduction

The [PUDB Python debugger](https://pypi.python.org/pypi/pudb) provides a colorful ncurses-based "text-GUI" debugger that can be called by the local Sage python interpreter to debug Python scripts that interface with built-in Sage functions and types. In this tutorial, we provide a small sample script that interfaces with Sage and detail howto debug with PUDB in this case. The separate non-math-related tutorial for PUDB located at [this link](http://heather.cs.ucdavis.edu/~matloff/pudb.html) is a primary reference here, though we only reproduce the highlights of that full introduction to PUDB in this tutorial. We also cover installation of the PUDB module with the separate local Python that comes bundled with Sage in the next section, which is somewhat different than installing the module with a package-manager such as apt. Another video tutorial giving a concise overview of the PUDB debugger is found at [this link](https://vimeo.com/5255125).

Installation of PUDB in Sage

The actual installation of the PUDB module in Python is straightforward once you know a couple of tricks about how the Sage shell can be used to install new packages in its own local chroot-like environment. In particular, assuming you have the OpenSSL development libraries installed on your system (try apt-get install libssl-dev on a Debian variant Linux box), we can issue the following commands in sequence to get Sage’s local Python to recognize the PUDB add-on:

     $ sage -i openssl
     $ sage -f python2
     $ sage -sh
     (sage-sh) pip install --upgrade pip
     (sage-sh) pip install pudb
     (sage-sh) exit

This method also works to install other Python add-on modules into Sage’s Python, for example, such as the useful memory_profiler module that is not yet installed in Sage by default. To verify that the install of PUDB is working correctly, consider any fairly simple Python script test-script.py and then issue the following command: $ sage -python -m pudb test-script.py This should bring up the

Add the sage-pudb alias to the local .bashrc

An Example Program

python.py
# i just wrote a comment in python
# and maybe one more

Core Features of PUDB

Shortcut Keys

Setting Breakpoints

Configuration of PUDB

Line Numbers

Configuring Printed Variable Representations

Other Sage Debugging Links

Clone this wiki locally