Jupyter kernels for R, gp, gap, etc

67 views
Skip to first unread message

Tim McLarnan

unread,
Aug 4, 2020, 12:26:38 AM8/4/20
to sage-support
I'm sure this is an uninformed question from an old man who is finally accepting that the old SageNB Notebooks are going away, and who is excitedly and very belatedly stepping into the new world of Jupyter.

On CoCalc or with the old SageNB Notebooks, there are lots of kernels to choose amongst. The Jupyter notebooks in the current OS X binaries only offer SageMath and Python kernels.  How does a fairly naive user install kernels for R, gp, and gap?  I would have expected them just to be there automatically, as they were with the old Notebooks.

I tried copying the kernel folders from CoCalc and editing them in what I thought was the right way and putting them with the kernel folders on my machine.  This produced kernels that show up in Jupyter, but that don't work.  No doubt someone who knows the right things to put in the .json files could make this work, but I can't.  This has to be an absurdly complicated approach, though.  Surely there's just some trivial thing I don't know about.

Apart from writing the occasional function in SageMath, I've never worked with Python or Jupyter.

I'd really like to have these kernels available, but I want to run a local SageMath installation because of unreliable Internet here in the woods.  I can stay with the old Notebooks, but I'd like to be able to grow as SageMath does.

--Tim

Nils Bruin

unread,
Aug 4, 2020, 2:21:32 AM8/4/20
to sage-support
On Monday, August 3, 2020 at 9:26:38 PM UTC-7, Tim McLarnan wrote:
I tried copying the kernel folders from CoCalc and editing them in what I thought was the right way and putting them with the kernel folders on my machine.  This produced kernels that show up in Jupyter, but that don't work.  No doubt someone who knows the right things to put in the .json files could make this work, but I can't.  This has to be an absurdly complicated approach, though.  Surely there's just some trivial thing I don't know about.

That got you the configuration of the kernels, but likely not the actual code that implements them. Jupyter kernels are basically stand-alone programs. Often, they are written in python (but they don't have to be!) and installing them consists of two steps: installing the software and informing the jupyter notebook installation of their presence.

For kernels written in python, you end up needing to install python software, for which there are excellent tools.

A very simple example, that I happen to have written myself, so that's why I'm familiar with it, but needs "magma" present on your machine to work.


The instructions indeed show two installation steps: one for installing the python package and the other for setting up the jupyter notebook registration.

To make extra kernels known to the *sage* jupyter notebook server, you have to make sure that you run the configurations in the sage copy of python. You'd want to do something like "sage -sh" (on linux or OSX) to get a shell that is set up with the sage environment, and run the configurations in there.

An alternative is to register the sage kernel with the system-wide jupyter notebook. This has the advantage that other kernels that come prepackaged with your OS distribution are easier to install (just use your OS tools). It has the big disadvantage that currently, rhis is still not a straightforward process; it requires some hackery, so I would not recomment it as your first experiment.

A big disadvantage of the python ecosystem is that one often end up with multiple copies of python living side-by-side on your OS and it's often hard to tell which version gets run for what.

Isuru Fernando

unread,
Aug 4, 2020, 2:35:02 AM8/4/20
to sage-s...@googlegroups.com
I suggest installing sage through conda. https://doc.sagemath.org/html/en/installation/conda.html

Conda is a package manager that runs on linux and osx and sagemath is available as a binary package. There are lots of jupyter kernels pre-packaged, so it's only a matter of typing,

      conda install sage=9.1 r-irkernel pari_jupyter gap

to get sage, R, gp, gap kernels.

Isuru

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/6e56fd3d-e424-4573-b3b2-b4aab46b88c0o%40googlegroups.com.
Message has been deleted

Tim McLarnan

unread,
Aug 5, 2020, 1:22:20 PM8/5/20
to sage-support

Thank you so much!  I’m almost there.

Isuru’s suggestion of using conda looked like it might be the simplest thing, but Nils’ post was very informative.  I’m learning good stuff.  Massive thanks to both of you!

So I installed conda, which installed Python 3.8.  I couldn’t then Sage 9.1, which requires at most Python 3.7, so I followed instructions at docs.sagemath.org and Isuru’s instructions:

conda create -n sage sage python=3.7

conda activate sage

conda install pari_jupyter

sage -notebook jupyter

This does just what I want.  It lets me open jupyter notebooks and move back and forth between sage and gp kernels, which appear in the list of kernels at the top of the notebook.  I did a little dance.

conda install gap

This had a small glitch.  gap seems to be compatible only with sage 9.0 and below, so the sage installation got downgraded.  OK, not a big problem.

conda install r-irkernel

The R kernel now appears in the list of kernels in the Jupyter notebook, but the R kernel doesn't work.  I can open a notebook that says it is using the R kernel.  The “kernel starting, please wait” button stays lit for a long time, but it eventually goes off.  There’s a button saying “R” with a filled circle next to which says “kernel connected” when I hover over it.  If I then type an R command, though, the line number stays at [*], and the command never runs.

Any ideas?

For anybody who’s still here and interested, here are some of the terminal error messages:

(sage) $ sage -notebook jupyter

…stuff…

[E 12:45:47.668 NotebookApp] Could not open static file ''

[W 12:45:47.746 NotebookApp] 404 GET /static/components/react/react-dom.production.min.js (::1) 11.12ms referer=http://localhost:8888/tree?token=4a282eb161cdecf2ed39967452d18ce894d4d45ce625ee6b

[I 12:46:24.906 NotebookApp] Creating new notebook in 

[W 12:46:25.389 NotebookApp] 404 GET /static/components/react/react-dom.production.min.js (::1) 1.69ms referer=http://localhost:8888/notebooks/Untitled2.ipynb?kernel_name=ir

[I 12:46:25.860 NotebookApp] Kernel started: ba682ba3-5032-4dc7-a549-088b9b5da955

Error in library.dynam(lib, package, package.lib) : 

  shared object ‘digest.dylib’ not found

Calls: :: ... loadNamespace -> namespaceImport -> loadNamespace -> library.dynam

Execution halted

…that got repeated 4 times, then…

[W 12:46:40.899 NotebookApp] KernelRestarter: restart failed

[W 12:46:40.899 NotebookApp] Kernel ba682ba3-5032-4dc7-a549-088b9b5da955 died, removing from map.

[W 12:47:25.925 NotebookApp] Timeout waiting for kernel_info reply from ba682ba3-5032-4dc7-a549-088b9b5da955

[E 12:47:25.927 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: ba682ba3-5032-4dc7-a549-088b9b5da955)


Message has been deleted

Tim McLarnan

unread,
Aug 5, 2020, 7:39:30 PM8/5/20
to sage-support
OK, the last mess was my error.  I had multiple versions of R installed, one by conda and an older global R.  Naturally this caused problems.  Getting rid of the older R solved the problem.  Everything is now good.  Thanks, all!
This whole process is still a bit daunting for us amateurs.  I wish it were as simple as it was with the old SageNB notebooks, where it just worked and I didn't need help from you wizards.
Reply all
Reply to author
Forward
0 new messages