sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.17k stars 216 forks source link

Improve wiki about how to use locally installed Sage via Jupyter kernel #2351

Open kedlaya opened 7 years ago

kedlaya commented 7 years ago

For Sage development purposes, it would be helpful to be able to use a locally installed copy of Sage as a kernel within a Jupyter notebook. Of course, this would be entirely at the user's risk (e.g., if your build of Sage deletes local data, don't blame us).

haraldschilly commented 7 years ago

I think this works, simply put the kernel in your project.

If it isn't explained here https://github.com/sagemathinc/cocalc/wiki/sagejupyter#-question-how-can-i-add-my-own-jupyter-kernel on that page we should improve it.

On Sep 5, 2017 11:37, "kedlaya" notifications@github.com wrote:

For Sage development purposes, it would be helpful to be able to use a locally installed copy of Sage as a kernel within a Jupyter notebook. Of course, this would be entirely at the user's risk (e.g., if your build of Sage deletes local data, don't blame us).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sagemathinc/cocalc/issues/2351, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMqLTd_QSR1fX77KAnZCJ4SL5wHXOGlks5sfRY7gaJpZM4PMr9- .

kedlaya commented 7 years ago

Aha, I hadn't found that.

I've never written a JSON file before, so I'm not sure exactly what the arguments should be in the case of a custom build of Sage in my home directory. Would it be possible to add an example to that documentation which specifically addresses this use case?

kedlaya commented 7 years ago

Also, where that documentation says "click the reload button (top right of the Jupyter notebook) to let it search for kernels and find your configuration", it should be something like "select 'Refresh Kernel List' from the Kernel menu to let the notebook search for kernels and find your configuration."

kedlaya commented 7 years ago

Since I figured this out, I should show my work in case this can be used to improve the documentation.

To figure out how to format the JSON file, I eventually figured out that I should look at the existing ones by doing jupyter kernelspec list. That gave me the directory to look at one of the JSON files for Sage itself, and copying that (and changing the path to the executable) was sufficient.

haraldschilly commented 7 years ago

Yes, the documentation is not well discoverable and likely outdated. We should update it, and yes, it won't hurt to add an explicit example. In any case, good to know that it did work as expected despite the troubles.

williamstein commented 7 years ago

To clarify: locally installed = installed into your own project.

williamstein commented 7 years ago

We can now also make it much easier and quicker to get a pre-built ready-for-dev/modification version of Sage: https://github.com/sagemathinc/cocalc/issues/2361

slel commented 7 years ago

If you have an extra SageMath install in your project and you want to add a kernel for it that works in the system-wide Jupyter install, read this answer to a Stackoverflow question: https://stackoverflow.com/questions/39296020/how-to-install-sagemath-kernel-in-jupyter/41595015#41595015

kedlaya commented 7 years ago

I had actually found that answer, but it didn't help me because I can't run "sudo" within a project and I wasn't sure how to modify the instructions appropriately. (I explained above what ended up working in the end.)

slel commented 7 years ago

I edited the StackOverflow answer about using --user instead of sudo.

The help page you get by typing in a terminal

jupyter kernelspec install help

gives you more options, e.g. change the name since on CoCalc the name "sagemath" is taken by the system SageMath kernel.

So you could do something like this (adapting KPATH and KNAME):

$ KPATH='/path/to/kernel/sagemath'
$ KNAME='SageMath (custom)'
$ jupyter kernelspec install $KPATH --user --name=$KNAME"
kedlaya commented 7 years ago

For the record, my kernel.json consisted of this line:

{"display_name": "SageMath (custom)", "argv": ["/home/user/sage/sage", "--python", "-m", "sage.repl.ipython_kernel", "--matplotlib=inline", "-f", "{connection_file}"]}