Python Debugging / Using PUDB with Sage

145 views
Skip to first unread message

Maxie Schmidt

unread,
Nov 26, 2016, 2:25:02 AM11/26/16
to sage-devel
I've been looking at GUI-based (or at least text-GUI-based) python debuggers to help with fixing bugs in a larger python code base. I came across PUDB (https://pypi.python.org/pypi/pudb), which is nice and runs python scripts. Does anyone know of a way to get PUDB to work with debugging Sage scripts, or python scripts that would usually be run through Sage? Otherwise, is there a way to get these modules installed into the python that comes bundled with Sage? I've run into some other road blocks before with getting a python profiler (https://pypi.python.org/pypi/memory_profiler) to work with my python scripts run through the Sage shell.

Thanks.

Maxie

Ralf Stephan

unread,
Nov 27, 2016, 1:51:40 AM11/27/16
to sage-devel
You didn't mention, have you seen http://doc.sagemath.org/html/en/developer/doctesting.html#debugging-tools?

On Saturday, November 26, 2016 at 8:25:02 AM UTC+1, Maxie Schmidt wrote

Ralf Stephan

unread,
Nov 27, 2016, 1:55:48 AM11/27/16
to sage-devel
Oops wrong link. Do the dev docs really have nothing about Python debugging?

Maxie Schmidt

unread,
Nov 28, 2016, 4:37:21 PM11/28/16
to sage-...@googlegroups.com

I'm looking for an ncurses-like GUI debugging tool. PUDB looks especially nice from what I can find online. Is there anything else like this for Sage? My searches came up empty.

There's sort of a secondary question buried in the first question I asked, which is how to get add-on modules, like the memory profiler and PUDB, installed into the python that's bundled with Sage. My understanding is that Sage runs the python code in scripts through a separate local version of python than whatever else would be installed on the system. It's easy enough to get extra python modules installed on my system, but these do not show up as modules available for use within Sage. So how do I install extra modules into the python used by Sage? Perhaps a chroot type of situation?

Maxie


On Nov 27, 2016 12:55 AM, "Ralf Stephan" <gtr...@gmail.com> wrote:
Oops wrong link. Do the dev docs really have nothing about Python debugging?

--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/G0hD31ZUwSw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+unsubscribe@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Maxie Schmidt

unread,
Nov 28, 2016, 4:41:28 PM11/28/16
to sage-...@googlegroups.com

Also, if the group can help me figure out how to get extra add-on python modules installed with Sage, I'd be happy to write up a tutorial on how to get the stock python memory profiler and PUDB working with Sage.

Maxie

mmarco

unread,
Nov 28, 2016, 5:32:55 PM11/28/16
to sage-devel
If this is of any help, this is what I use:

Maxie Schmidt

unread,
Nov 29, 2016, 7:58:09 AM11/29/16
to sage-devel
Here is the solution I eventually found to get pudb installed with Sage:

1) Install libssl-dev: $ sudo apt-get install libssl-dev
2) Install OpenSSL: $ sage -i openssl
3) Recompile: $ sage -f python2
4) Run the Sage shell: $ sage -sh
5) (sage-sh) pip install --upgrade pip
6) (sage-sh) pip install pudb

Then we can finally run: $ sage -python -m pudb pudb-script.py,
where my simple pudb.py script looks something like the following:
import pudb; pudb.set_trace()                    
print "My PUDB Example ... "

Maxie

Maxie Schmidt

unread,
Dec 9, 2016, 11:07:18 AM12/9/16
to sage-devel
For the sake of completeness, I'm adding a link to a SMC wiki tutorial on using PUDB with Sage (for both local source installs and within the SMC terminal application):
https://github.com/sagemathinc/smc/wiki/Using-a-GUI-Python-Debugger-with-Sage-(PUDB).

Maxie

William Stein

unread,
Dec 9, 2016, 12:59:31 PM12/9/16
to sage-devel
On Fri, Dec 9, 2016 at 8:07 AM, Maxie Schmidt <max...@gmail.com> wrote:
> For the sake of completeness, I'm adding a link to a SMC wiki tutorial on
> using PUDB with Sage (for both local source installs and within the SMC
> terminal application):
> https://github.com/sagemathinc/smc/wiki/Using-a-GUI-Python-Debugger-with-Sage-(PUDB).
>

Thanks. I made a change to the example program typesetting so it is
possible to copy/paste it out (it wasn't the way you had it due to a
single extra space in front of every line).
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

William Stein

unread,
Dec 9, 2016, 1:17:11 PM12/9/16
to sage-devel
--
William (http://wstein.org)
Screen Shot 2016-12-09 at 10.13.21 AM.png

William Stein

unread,
Dec 9, 2016, 1:20:00 PM12/9/16
to sage-devel
Also, pudb is now pre-installed systemwide so `pip install pudb` is no
longer needed....
--
William (http://wstein.org)

William Stein

unread,
Dec 9, 2016, 1:20:38 PM12/9/16
to sage-devel
And if you do "sage -sh" first, then it'll use a different pudb
installed into sage.

(sorry for spamming the list)
--
William (http://wstein.org)

Dima Pasechnik

unread,
Dec 9, 2016, 2:43:52 PM12/9/16
to sage-devel


On Friday, December 9, 2016 at 4:07:18 PM UTC, Maxie Schmidt wrote:
For the sake of completeness, I'm adding a link to a SMC wiki tutorial on using PUDB with Sage (for both local source installs and within the SMC terminal application):
https://github.com/sagemathinc/smc/wiki/Using-a-GUI-Python-Debugger-with-Sage-(PUDB).

thanks, great. I wonder where to put a link to this on wiki.sagemath.org
(the corresponding part of the wiki is horribly outdated...)

Perhaps this can be made a part of Sage doc instead?

Maxie Schmidt

unread,
Dec 9, 2016, 4:48:42 PM12/9/16
to sage-...@googlegroups.com
I didn't do much with setting traces / breakpoints from within the Python code itself in the tutorial. You can call from pudb import set_trace as bp; bp() to launch the pudb debugger at a certain point in the code. This should simplify having to manually add all of the breakpoints from within the PUDB GUI. There's also a "saved-breakpoints-2.7" file stored in ~/.config/pudb/ that stores previously set breakpoints, but which could be problematic if the line numbers change in the code. I will add a note about this in the tutorial. 

Maxie

--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/G0hD31ZUwSw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages