This would be a very useful utility (I'm teaching Programming Languages). But, when trying to use showast on a server (no DISPLAY is set) running JupyterHub you get this error:
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-8-389e57529b45> in <module>()
----> 1 get_ipython().run_cell_magic('showast', '', '\n1 + 1')
/opt/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2113 magic_arg_s = self.var_expand(line, stack_depth)
2114 with self.builtin_trap:
-> 2115 result = fn(magic_arg_s, cell)
2116 return result
2117
/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in showast(__, cell)
154 def showast(__, cell):
155 m = ast.parse(cell)
--> 156 show_ast(m)
157
158
/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in show_ast(module)
148 else:
149 treestring = nltk_treestring(module)
--> 150 tree_image(treestring)
151
152
/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in tree_image(tree)
122 def tree_image(tree):
123 t = Tree.fromstring(tree)
--> 124 tv = SizableTreeView(t)
125 tv._cframe.print_to_file('.temp.ps')
126 im = Image.open('.temp.ps')
/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in __init__(self, *trees)
86 self._trees = trees
87
---> 88 self._top = Tk()
89
90 cf = self._cframe = CanvasFrame(self._top)
/opt/anaconda3/lib/python3.5/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
1866 baseName = baseName + ext
1867 interactive = 0
-> 1868 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1869 if useTk:
1870 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
This seems like a roundabout way to get a graphical representation. Any ideas for a workaround?
BTW, an SVG would be preferable as an image format.