Install and use Leointeg with Anaconda python

63 views
Skip to first unread message

Matt Wilkie

unread,
Jul 6, 2020, 12:56:34 AM7/6/20
to leo-editor
My notes from getting vscode and Leointeg working today. Both tools are completely new to me.

Chocolatey and Miniconda/Anaconda setup recipe for leointeg, a plugin to enable Visual Studio Code to use Leo Editor as an engine for working with outlines and nodes and clones. 

 

Starting point: a Win10 admin command prompt with Chocolatey installer, Conda, and Git in PATH.  I pinned python to 3.6 as that is Leo's current minimum python version. Adjust to suit your preference.

 

Admin prompt

 

:: Install Visual Studio Code & python support, Node.js

choco install vscode vscode-python nodejs

 

Normal command prompt:

 

:: Create anaconda environment for Leo & Leo-integ

conda create -n vscode-leo

conda activate vscode-leo

conda install python=3.6

 

:: Install Leo & dependencies

pushd code

pip install --editor .\leo-editor

 

:: Install Leointeg python dependencies

pip install websockets

 

:: Install Leointeg & Node.js dependencies

git clone https://github.com/boltex/leointeg

cd leointeg

npm install

npm audit fix

 

Run vscode

 

Open Folder >> path\to\leointeg

"This workspace has extension recommendations" >> Install All

 

Open command pallete [Ctrl-Shift-P]

  • type "select inter" and chose "Python: Select interpreter" from the list. Status bar will indicate search for and caching of python environments, followed by list of conda environments. >> Choose the leointeg one, e.g.

 

c:\tools\miniconda3\envs\vscode-leo\python.exe

 

  • Using same technique, change 'Default Terminal' to Command Prompt instead of Powershell. (Apparently if you use Powershell there's more manual things to do.)

 

Run Extension

  • [Ctrl-Shift-D] to open debugger side panel, then
  • Press play button (right pointing green triangle) - [F5]

 

Vscode will open a new window in foreground. The background vscode window should have a highlighted bottom status bar and show the leointeg conda python environment.

 

The foreground window should be titled "Extension Development Host". From it Open Folder and point to your Leo stuff. A "Welcome to Leointeg" page opens.

 

Switch back to the original vscode window. Open a terminal in vscode [Ctrl-Shift-`] and start the leobridge server manually.

 

python leobridgeserver.py

 

Now switch to the dev host and in left hand menu >> Leo Integration >> [Connect to Server].

 

When connection is established an [Open Leo File] button should replace [Connect to Server].

 

….

 

When things don't work, look to the [Debug Console] panel in the original Vscode window.

 

What seems to be needed in every new vscode session:

 

  1. Selecting the python interpreter
  2. Running "python leobridgsever.py"

 

I'm confident there's a way to automate this, somewhere.

 

 

Sources

 

 

 

Edward K. Ream

unread,
Jul 6, 2020, 6:10:31 AM7/6/20
to leo-editor
On Sun, Jul 5, 2020 at 11:56 PM Matt Wilkie <map...@gmail.com> wrote:

> My notes from getting vscode and Leointeg working today. Both tools are completely new to me.

Thanks Matt. This will help Leonistas start playing with Félix's work.

> Switch back to the original vscode window. Open a terminal in vscode [Ctrl-Shift-`] and start the leobridge server manually.

 

python leobridgeserver.py

 

Interesting you should mention this.  It shouldn't be necessary because (as you say) after running leoInteg you will see (by default) two buttons when you select the Leo icon on the left margin: "Connect to server" and "Start Server". Below those buttons you will see "View leoInteg's configuration settings."


On Linux, the "Start Server" button doesn't work, but starting leobridgeserver.py manually does work. A line containing an fstring fails, so presumably leoInteg is using python 2 instead of 3. This despite a configuration that says run "python", which on my machine does in fact run python 3.


Ok. I got things to work on Linux. The default python is supposed to be "python3" on Linux, but I had to enter "python3" explicitly.


Hold on a second. The configuration settings link brings up the configuration settings, but it appears that the settings page doesn't show the present settings!! For me, right now, the extension is acting properly and automatically starts the server and connects to it. So I see the "Open Leo File" button. But that's not what is showing in the configuration page!


Hold on another second. When I reload vs code I now do see the settings I entered.


Tentative Conclusion


Changing settings does work, but the configuration settings link won't show the updated settings under some circumstances. Maybe this also happens on Windows, but I've only seen this on Linux.


These problems would be very hard for Félix to find, because everything works for him, so he's not changing settings.


> What seems to be needed in every new vscode session:

 

  1. Selecting the python interpreter
  2. Running "python leobridgsever.py"

See my tentative conclusions above. Our confusions are the normal growing panes for new software.

Edward

Félix

unread,
Jul 6, 2020, 8:11:41 AM7/6/20
to leo-editor
Hi Matt,

Thanks again for your contributions that will greatly improve leoIntegs documentation, and handling of Miniconda/Anaconda python installations people might have.

I just noticed you ran "npm audit fix" after running "npm install" so i'm not sure what dependency might have been raised to a version that might be problematic.

To try without those upgrades, just delete the node_modules folder to reset all dependencies, make sure to revert to a clean master or dev branch commit state, (no modifications of package.lock.json etc.)

and then run npm install (without running "npm audit fix")

Also, (as stated elsewhere), I also forgot to mention Leo's devel branch should be used with Leo, for multi-file support, until it's next release.

Many thanks again! 
--
Félix

Matt Wilkie

unread,
Jul 6, 2020, 12:41:28 PM7/6/20
to leo-editor

I just noticed you ran "npm audit fix" after running "npm install" so i'm not sure what dependency might have been raised to a version that might be problematic.

Interesting. The first time I ran `npm install` in red text it reported 320 vulnerabilities 70 of which were severe. (I neglected to capture the log, so the 70 number is not exact.) 

I removed `leointeg\node_modules` and ran npm install again. This time it reported only 11 low severity vulnerabilities:

added 1034 packages from 542 contributors and audited 1104 packages in 47.144s

17 packages are looking for funding
  run
`npm fund` for details

found
11 low severity vulnerabilities
  run
`npm audit fix` to fix them, or `npm audit` for details


After this there is no change to the previous reported behaviour.

 
Also, (as stated elsewhere), I also forgot to mention Leo's devel branch should be used with Leo, for multi-file support, until it's next release.

Good to know. I am using Leo devel branch with leointeg, but heretofore that was by habit and not intention. ;-)


Many thanks again!
 
You're welcome. Thanks for introducing me to vscode. Before now I had ignored it as I'm happy enough with the tools I know (Leo, Notepad++, Pyzo). Vscode has much to recommend it, and I'm happy to be exploring that first hand.

-matt

Félix

unread,
Jul 6, 2020, 4:22:55 PM7/6/20
to leo-editor
Hmm...

Choosing which python to use in vscode says to me you want to start the leobridge server via the vscode debugger (see debug panel, open top dropdown and choose 'run both') which renders the 'auto start' setting via leoInteg setting totally superflous in that case, and should be kept disabled, otherwise it will also try to start a server via node's "child.spawn(w_pythonPath, w_args);" (see serverManager,ts line 57) and you will get the "port in use" message.

Until this extension is released as a compiled package, for convenience, there are 3 different ways to start a leobridge server with leointeg. 

I realize I should clarify and document this, because what I gather from reading Matt's and Ar-Jan's is that I cannot determine which of those 3 ways they are going for at any given time. And mixing them up doesn't help running smoothly... Seems that this concept is not taken into account and its my fault to not having made all that crystal clear in the documentation.

I'm finishing some other stuff and I will adres this in more details later. I just wanted to state the above real quick bluntly while i'm thinking about it. 

ok back to work now I'll give more updates tonight.
--
Félix

Félix

unread,
Jul 8, 2020, 5:56:12 PM7/8/20
to leo-editor
Hi Matt, 

In this Thread, Ar-jan tells me the command 'start server' works form leoInteg. https://github.com/boltex/leointeg/issues/10#issuecomment-654152125

That's the same command that is launched as when the 'start server automatically' is set.

So unless i'm mistaken he seems to have found a good procedure or command line entry to set in the leointeg's options, in order to start the server via the leoInteg extension, as would someone who uses a 'compiled' version of the extension from the vscode 'online market'.

Just to clarify, theres 3 (even 4 or 5) ways to start the leobridgeserver.py server, 
1- through vscode's debugger (F5 with the "server and extension" profile selected) (that requires installing python extensions and all that, which should not be required for someone using the extension for non-python stuff and not wanting to debug it while it runs, such as a casual leo user writing html, text, or non-python code)
2-through vscodes (original window - not the extension host) 's terminal.
3- through your OS'es generic console terminal like you would any other utility. 
4- through leoIntegs's 'start server' command which is just a 'launch process', (same as setting the 'start server automatically' in the options, as stated above) 
5- through vscode (the extension host this time) 's terminal window.

(With the goal being of ultimately finding a way for #4 in this list )

People pressing F5 (start debuging) need to check which debug profile they're on first! otherwise they might have started a server and then get another 'port in use' error when actually also having leoInteg itself try to start a server instance on your machine.

So please take the time to go through the thread mentionned in leoIntegs issues (#10) if you haven't already, (or if you have, maybe new info was added.)

Anyways i'm just throwing all that info here in case it brings something to light that may have been overlooked and I'm very grateful for the time and effort you've placed in trying to make a guide for conda/anaconda users. (i'm very much ignorant about those)

I intend to address the documentation and provide better support for conda/anaconda users so any help is appreciated!

Thanks Again Matt! 
--
Félix


On Monday, July 6, 2020 at 12:41:28 PM UTC-4, Matt Wilkie wrote:

Félix

unread,
Jul 10, 2020, 3:38:26 PM7/10/20
to leo-e...@googlegroups.com
Just copy/pasting here from the leoInteg issues in case people are lookinghere for details about this : another description of the possible ways to start a server for leoInteg in this development version and environment that people are currently using it. 

(finished product will not have all those possibilities which will remove the possible confusion) 

Leointeg's Python Command configuration set to python and Running the extension with the Server and Extension option are mutually exclusive: I have not explained those concepts clearly - and as I wanted to give more options for tester than less, it seems people are mix and matching those methods of starting the server in erroneous ways.


So to clarify: if you're running the extension with the "Server and Extension", then, the python command could be set to 'potato' it wouldn't matter because it's not used then. That would be using the debug profile in the .vscode/launch.json file. which I encourage you to open and see for yourself what those 3 debugging profiles are,. those will not exist at all when the extension is compiled and distributed as a real extension.


So this is important to distinguish: to simulate a real, finished extension, select 'run extension' only in the run/debug menu. this will force you to either :
1- set leoInteg option to start server automatically with the provided python command, both being in the leoInteg settings.
2- start a server by typing leobridgeserver.py in a terminal.

If you instead select "server AND extension" in the run/debug panel, then, vscode will run and debug the server by itself, as if vscode itself was considering the server program as it's main project. and will use whichever python debug setting vscode's debugger is set to. Not the leoInteg options!


So...Either configure a python command line setting in leo Integs settings, and use the 'run extension' only in the run/debugger dropdown. OR , don't start server automatically, and use the "start both server and extension" in the run/debuger dropdown instead. (ok to connect automatically though, doesn't matter how the server was started to connect to it automatically)


Again, sorry English is not my native language. (i guess i should capture myself as a screencast while explaining this)

--

Félix

Edward K. Ream

unread,
Jul 10, 2020, 3:54:04 PM7/10/20
to leo-editor


On Fri, Jul 10, 2020 at 2:38 PM Félix <felix...@gmail.com> wrote:

> So...Either configure a python command line setting in leo Integs settings, and use the 'run extension' only in the run/debugger dropdown. OR , don't start server automatically, and use the "start both server and extension" in the run/debuger dropdown instead. (ok to connect automatically though, doesnt matter how the server was started to connect to it automatically)

Thanks for this summary.

Edward

Matt Wilkie

unread,
Jul 11, 2020, 4:24:05 AM7/11/20
to leo-editor

Leointeg's Python Command configuration set to python and Running the extension with the Server and Extension option are mutually exclusive: I have not explained those concepts clearly - and as I wanted to give more options for tester than less, it seems people are mix and matching those methods of starting the server in erroneous ways.


So to clarify: if you're running the extension with the "Server and Extension", then, the python command could be set to 'potato' it wouldn't matter because it's not used then.


Ahhh!  the light dawns, thanks!

I don't know if these are helpful at all, but I wrote some Leo script buttons to start, stop & list Vitalije's history tracer extension from inside Leo. The tracer server runs as external background process. https://gist.github.com/maphew/9c2b505f5f550f8b674058bb71b2cb60 for the current code, and intro thread here.

-matt


Reply all
Reply to author
Forward
0 new messages