Success! Executing sage scripts from Leo!!!

22 views
Skip to first unread message

Edward K. Ream

unread,
Oct 16, 2024, 10:08:51 AM10/16/24
to leo-editor

It is possible to use Leo as a sage notebook (within Ubuntu, not wsl). Right now, without changing Leo!


Two, no three, Ahas make this possible:


- Leo must run within Sage.

- Everything must be installed within Sage.

- Sage prompts are really ipython prompts.


Installing Leo


I installed Leo inside Sage:


sage: !pip install leo


The first time I ran Leo I got a familiar message:


sage: !leo

qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found...


But now I knew what to do:


sage: !sudo apt-get install libxcb-cursor0


And now Leo worked!


sage: !leo

setting leoID from os.getenv('USER'): 'edreamleo'

Leo 6.8.1, 6.8.1 branch, build 616c868bbf

2024-07-24 05:19:21 -0500

Python 3.12.3, PyQt version 6.7.3

linux

wrote recent file: /home/edreamleo/.leo/.leoRecentFiles.txt


Executing Sage scripts within Leo


Here is a script from the Sage tutorial:


from sage.all import *

x = circle(

    (Integer(0),Integer(0)), Integer(1),

    rgbcolor=(Integer(1),Integer(1),Integer(0)))

print('x', x)

x.show()


When Leo runs inside sage we can run this script as a Leo script!! The output (in the Sage console) is:

x Graphics object consisting of 1 graphics primitive

Graphics object consisting of 1 graphics primitive


The graphic doesn't appear automatically, but I expect it will after configuring Sage's viewer.


Summary

Sage runs ipython in a separate environment, so:

- Installing packages outside Sage is futile.
- Leonine scripts can import sage only when Leo runs from within Sage.

With these insights, Leo becomes a Sage notebook!

All comments and questions are welcome.

Edward

Edward K. Ream

unread,
Oct 16, 2024, 10:41:06 AM10/16/24
to leo-editor
On Wednesday, October 16, 2024 at 9:08:51 AM UTC-5 Edward K. Ream wrote:

It is possible to use Leo as a sage notebook (within Ubuntu, not wsl). Right now, without changing Leo!


Some follow-on ideas about IPython:

- Running Leo from Sage may be a much better way of integrating Leo and IPython than Leo's IPython plugin.
- IPython magics and the IPython Cookbook may offer further nifty options for integrating Sage and Leo.

These are early days. The possibilities are exciting.

There is another set of possibilities to explore: running sage within vs-code. However, it seems unlikely that Leo-JS can be integrated into sage as easily as Leo itself. We shall see.

Edward
Reply all
Reply to author
Forward
0 new messages