Ask Your Question

Revision history [back]

no graphics output when running python script via "sage -python script.py"

Hi, am writing a GUI for a python module that relies on Sage packages, so it needs to run from a terminal using sage, i.e., "sage -python programGUI.app". In the command line version of the program everything I need works great, but when I try to launch a graphic from the GUI, nothing launches. For 2d graphics I can save them to a tmp directory, then open in the GUI or elsewhere (i.e., a workaround). But for 3d graphics, which I would like to open in a browser with the option viewer="threejs", I don't see a way to save the html file that Sage generates.

The sage documentation for threejs says "The generated HTML file contains all data for the scene apart from the JavaScript library and can be saved to disk for sharing or embedding in a web page", but I don't see any way to save the HTML file to disk. When I launch a graphic in the sage command line environment the HTML file is saved to SAGE_TMP. In the below example, no file is saved to the SAGE_TMP directory, which is presumably connected to the reason the browser does not launch the html page.

Here is a very simple example that shows that nothing is saved to the SAGE_TMP directory, and for which no graphic launches:

from sage.all import *

import os

tmp = str(sage.misc.misc.SAGE_TMP)
print(tmp)
os.listdir(tmp)

S=sage.plot.plot3d.shapes.Sphere(.5)
p=S.plot()
p.show(viewer='threejs',online=True)

os.listdir(tmp)

This returns:

/Users/will/.sage/temp/williams-MacBook-Pro.local/74189
Graphics3d Object

Thanks for any help anyone can give.