Is this a reasonable Leo Programming Hello World?

65 views
Skip to first unread message

Steve Litt

unread,
Dec 17, 2019, 8:40:59 AM12/17/19
to leo-editor
Hi all,

Is the attached hello.leo a reasonable Hello World for using Leo to
write Python programs?

Thanks,

SteveT

Steve Litt
December 2019 featured book: Rapid Learning for the 21st Century
http://www.troubleshooters.com/rl21
hello.leo

Matt Wilkie

unread,
Dec 17, 2019, 4:28:35 PM12/17/19
to leo-editor
it could be made portable with

import leo.core.leoGlobals as g
@path = g.computeHomeDir() # yields '/home/slitt' or 'C:\Users\slitt'

Also, if it's a Leo script (as distinct from a python script that could be run without Leo) this will print to both the starting console (stdout) and to Leo's log pane:

g.es_print('Hello World')

-matt

Steve Litt

unread,
Dec 17, 2019, 8:48:43 PM12/17/19
to leo-e...@googlegroups.com
On Tue, 17 Dec 2019 13:28:34 -0800 (PST)
Matt Wilkie <map...@gmail.com> wrote:

> it could be made portable with
>
> import leo.core.leoGlobals as g
> @path = g.computeHomeDir() # yields '/home/slitt' or 'C:\Users\slitt'
>
> Also, if it's a Leo script (as distinct from a python script that
> could be run without Leo) this will print to both the starting
> console (stdout) and to Leo's log pane:
>
> g.es_print('Hello World')
>
> -matt

Thanks matt,

Your solution ran perfectly when I highlighted line "@clean
helloclean.py" and pressed Ctrl+b, but when I ran the program created
by Leo, /home/slitt/helloclean.py, I got the following error trace:

Traceback (most recent call last):
File "helloclean.py", line 2, in <module>
import leo.core.leoGlobals as g
ModuleNotFoundError: No module named 'leo'

The best I could find after 15 minutes of web searching was:

* Rename pyproject.toml or otherwise

* At any rate, editing sys.path was the fix (commit d3a6494).

So I renamed pyproject.toml, and I put an import sys before importing
leo.core.leoGlobals, but same symptom.

I installed from your git page, the latest master, and I installed in
~/build, so /home/slitt/build/leo-editor-master/leo-core.cfg is a file.
In ~/.leo I could find nothing that referenced
/home/slitt/build/leo-editor-master , and I have a hunch that's the
problem but I can't figure it out farther.

Matt Wilkie

unread,
Dec 18, 2019, 11:51:04 AM12/18/19
to leo-editor
I think I made the code more complicated than needed. `Import leo` etc. is only needed if the file will be called outside Leo, e.g. `python hello-world.py`. This should work in a node by itself with ctrl-b:

g.es_print(g.computeHomeDir())


Traceback (most recent call last):
  File "helloclean.py", line 2, in <module>
    import leo.core.leoGlobals as g
ModuleNotFoundError: No module named 'leo'

pip install --editable  /home/slitt/build/leo-editor-master

Will add `leo.egg-link` in `PYTHONHOME/Lib/site-packages` which enables `import leo` to work. The egg-link file contains the path to the code directory, so editing sys.path shouldn't be needed.

You might need to use `pip install --user ...` on linux.

-matt

Steve Litt

unread,
Dec 19, 2019, 8:11:15 AM12/19/19
to leo-e...@googlegroups.com
On Wed, 18 Dec 2019 08:51:04 -0800 (PST)
Matt Wilkie <map...@gmail.com> wrote:

> I think I made the code more complicated than needed. `Import leo`
> etc. is only needed if the file will be called outside Leo, e.g.
> `python hello-world.py`.

Yes. My need is to say python3 hello-world.py .

I want to produce software others can use without Leo.


> This should work in a node by itself with
> ctrl-b:
>
> g.es_print(g.computeHomeDir())

Yes. When I ctrl+b, I indeed get the correct answer in the upper right
panel.


>
>
> Traceback (most recent call last):
> > File "helloclean.py", line 2, in <module>
> > import leo.core.leoGlobals as g
> > ModuleNotFoundError: No module named 'leo'
> >
>
> pip install --editable /home/slitt/build/leo-editor-master

I'd *really* prefer not to do that. I'm not a fan of pip, preferring to
get all my packages from my distro, Void Linux. I would jump through a
lot of hoops to avoid pip.


>
> Will add `leo.egg-link` in `PYTHONHOME/Lib/site-packages` which
> enables `import leo` to work. The egg-link file contains the path to
> the code directory, so editing sys.path shouldn't be needed.

I searched but couldn't find an example copy of leo.egg-link, and as I
mentioned, prefer not to use pip.

I'm willing to edit sys.path. Do you know how I can do that?

Thanks for your help, Matt.

Matt Wilkie

unread,
Dec 20, 2019, 3:32:18 PM12/20/19
to leo-editor

> Will add `leo.egg-link` in `PYTHONHOME/Lib/site-packages` which
> enables `import leo` to work. The egg-link file contains the path to
> the code directory, so editing sys.path shouldn't be needed.

I searched but couldn't find an example copy of leo.egg-link, and as I
mentioned, prefer not to use pip.

My Windows egg-link file (PYTHONHOME\Lib\site-packages\leo.egg-link):

D:\code-maphew\leo-editor
.

An alternative is to sym- or hardlink "{extracted code location}/leo-editor-master/leo" to "$PYTHONHOME/Lib/site-packages/leo".


In both cases to launch Leo from command line a wrapper needs to be put in "$PYTHONHOME/Scripts" that resembles launchLeo.py from repo root:

#!/usr/bin/env python
""" Leo launcher script A minimal script to launch leo """
import leo.core.runLeo
leo
.core.runLeo.run()

Also important to know is that only ./leo and subfolders count for anything. The repo root folder is invisible and ignored.

Hope that helps!

-matt









Reply all
Reply to author
Forward
0 new messages