Launching Leo when SageMath starts (Ubuntu)

156 views
Skip to first unread message

Edward K. Ream

unread,
Oct 17, 2024, 1:55:27 PM10/17/24
to leo-editor
The following sage.init file launches sage.leo when SageMath starts:

from subprocess import Popen
leo_path = '/home/edreamleo/sage.leo'
proc = Popen([f"leo {leo_path}"],
    shell=True, stdin=None,
    stdout=None, stderr=None, close_fds=True)

Sage continues to run without blocking. The only glitch is that I must click on the sage console and hit <return> to see a sage prompt.

As reported earlier, scripts such as the following run within Leo:

import sage.all as sage
from sage.all import Integer, plot
y = sage.circle(
    (Integer(0),Integer(0)), Integer(1),
    rgbcolor=(Integer(1),Integer(1),Integer(0)))
print(y)

The print statement works, but neither of the following statements works:

y.show()
y.plot()

Getting the plot statement to show the expected plot is my next project.

I have hopes: SageMath uses huge IPython libraries that should be accessible to Leo.

Summary

SageMath can launch Leo automatically on startup.

Leonine scripts in that Leo can successfully sage scripts.

IPython libraries promise to solve any imaginable problem.

Edward

P.S. A Milestone: My Linux workflow is roughly as convenient as my Windows workflow.

EKR

Thomas Passin

unread,
Oct 20, 2024, 4:02:48 PM10/20/24
to leo-editor
On Thursday, October 17, 2024 at 1:55:27 PM UTC-4 Edward K. Ream wrote:
import sage.all as sage
from sage.all import Integer, plot
y = sage.circle(
    (Integer(0),Integer(0)), Integer(1),
    rgbcolor=(Integer(1),Integer(1),Integer(0)))
print(y)

The print statement works, but neither of the following statements works:

y.show()
y.plot()

Getting the plot statement to show the expected plot is my next project.

Edward K. Ream

unread,
Oct 20, 2024, 7:18:25 PM10/20/24
to leo-e...@googlegroups.com
On Sun, Oct 20, 2024 at 3:02 PM Thomas Passin wrote:

> EKR: Getting [SageMath's] plot statement to show the expected plot is my next project.

That project is on hold indefinitely.


Thanks for the link.

Edward

Thomas Passin

unread,
Oct 21, 2024, 12:30:44 AM10/21/24
to leo-editor
Despite Edward's interest moving on from Sage, here are a couple of tips that may be helpful with other projects too.  Firstly one can run Sage scripts from within Leo without launching it inside Sage. The method given above doesn't provide any communication between Sage and Leo so we might as well just run Leo stand-alone.

There is one problem: if you install Leo into a venv instead of into the system Python's installation - as you should - then the venv's python will not know about sage.  Here's how to make it work. Before running Leo set PYTHONPATH to point to the site-packages  directory of your venv. Then launch Leo as you normally do - using the system's Python install, not the venv's. For my particular VM, here's the command:

export PYTHONPATH=/home/tom/venv/leo/lib/python3.12/site-packages:/home/tom/git/leo-editor

In this case I also included m git clone of Leo-Editor so I didn't need to cd to its directory first.

The second things that the little sage program in Edward's post created a graphics primitive but showed nothing.  The graphic can be saved as a png file and viewed with VR3.  In fact, we can mix RsT and Python code together and execute and render it with  VR3.  A screen shot is attached.
sage-vr3-demo.png
Reply all
Reply to author
Forward
0 new messages