How to use notebook in sage 9.0?

75 views
Skip to first unread message

Szabolcs Horvát

unread,
May 6, 2020, 5:58:09 PM5/6/20
to sage-support
I use sage 9.0 and sage 8.9 on macOS. I compiled them myself so I would gain access to other ILP solvers than GLPK.

They work fine in command line mode. But if I start Sage 9.0 as sage --notebook, it gives me an interface to create a new notebook, which only has the kernel "Sage 8.9".  How can I get the Sage 9.0 kernel?

This help page is not helpful:


It does not explain how to install the kernel.

Dima Pasechnik

unread,
May 6, 2020, 6:11:50 PM5/6/20
to sage-support
On Wed, May 6, 2020 at 6:58 PM Szabolcs Horvát <szho...@gmail.com> wrote:
>
> I use sage 9.0 and sage 8.9 on macOS. I compiled them myself so I would gain access to other ILP solvers than GLPK.
>
> They work fine in command line mode. But if I start Sage 9.0 as sage --notebook, it gives me an interface to create a new notebook, which only has the kernel "Sage 8.9". How can I get the Sage 9.0 kernel?

sage -notebook=jupyter

should give you jupyter notebook.

sagenb would only work with Python2 Sage (by default Sage 9.0 is built
with Python3, not 2)


>
> This help page is not helpful:
>
> https://doc.sagemath.org/html/en/reference/repl/sage/repl/ipython_kernel/install.html
>
> It does not explain how to install the kernel.
>
> --
> 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/f8bf42ac-11d2-4c19-a16c-6a9caa6960f2%40googlegroups.com.

Szabolcs Horvát

unread,
May 6, 2020, 6:19:35 PM5/6/20
to sage-support


On Wednesday, 6 May 2020 20:11:50 UTC+2, Dima Pasechnik wrote:
On Wed, May 6, 2020 at 6:58 PM Szabolcs Horvát <szho...@gmail.com> wrote:
>
> I use sage 9.0 and sage 8.9 on macOS. I compiled them myself so I would gain access to other ILP solvers than GLPK.
>
> They work fine in command line mode. But if I start Sage 9.0 as sage --notebook, it gives me an interface to create a new notebook, which only has the kernel "Sage 8.9".  How can I get the Sage 9.0 kernel?

 sage -notebook=jupyter

should give you jupyter notebook.

sagenb would only work with Python2 Sage (by default Sage 9.0 is built
with Python3, not 2)


Yes, I do get a Jupyter page in the browser, but not a notebook. In order to create a notebook, one must click "New" and choose the Jupyter kernel to use. There is no Sage 9.0 kernel there. There are some of the Python kernels I use independently of Sage, and there is Sage 8.9. How can I install the Sage 9.0 kernel? Is there documentation on this?

Dima Pasechnik

unread,
May 6, 2020, 6:32:49 PM5/6/20
to sage-support
this looks like a conflict between two versions of Sage (more
precisely, of jupyter).

Not sure how this can happen, though. You migh try to start "sage -sh"
of your Sage 9.0 and at its
prompt start

jupyter-notebook

it should give you an option to open URL of the shape
http://localhost:8888/?token=....

where you should ge the correct jupyter kernel (hopefully)
> --
> 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/4feab8f6-c3dc-450d-92c3-95039aa1d7e2%40googlegroups.com.

Szabolcs Horvát

unread,
May 6, 2020, 7:54:16 PM5/6/20
to sage-s...@googlegroups.com
Thanks for the help Dima, but sadly, even this did not work :-( Is there a simple way to set up the kernel manually?

You received this message because you are subscribed to a topic in the Google Groups "sage-support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-support/X5sXp3a-TmA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/CAAWYfq1viv3gEHKxfPCRqLBmvFc9gOsCKJiu1c_s_yQoDF8XWg%40mail.gmail.com.

John H Palmieri

unread,
May 6, 2020, 10:41:43 PM5/6/20
to sage-support
Silly question, but are you sure you are starting up Sage 9.0 when you do all of this ("sage --notebook" or "sage --sh")? If you give an explicit path to the Sage 9.0 version, does that help? Do you have any Sage-related environment variables which could be interfering with things?


On Wednesday, May 6, 2020 at 12:54:16 PM UTC-7, Szabolcs Horvát wrote:
Thanks for the help Dima, but sadly, even this did not work :-( Is there a simple way to set up the kernel manually?

On Wed, 6 May 2020 at 20:32, Dima Pasechnik <dim...@gmail.com> wrote:
this looks like a conflict between two versions of Sage (more
precisely, of jupyter).

Not sure how this can happen, though. You migh try to start "sage -sh"
of your Sage 9.0 and at its
prompt start

jupyter-notebook

it should give you an option to open URL of the shape
http://localhost:8888/?token=....

where you should ge the correct jupyter kernel (hopefully)


On Wed, May 6, 2020 at 7:19 PM Szabolcs Horvát <szho...@gmail.com> wrote:
>
>
>
> On Wednesday, 6 May 2020 20:11:50 UTC+2, Dima Pasechnik wrote:
>>
>> On Wed, May 6, 2020 at 6:58 PM Szabolcs Horvát <szho...@gmail.com> wrote:
>> >
>> > I use sage 9.0 and sage 8.9 on macOS. I compiled them myself so I would gain access to other ILP solvers than GLPK.
>> >
>> > They work fine in command line mode. But if I start Sage 9.0 as sage --notebook, it gives me an interface to create a new notebook, which only has the kernel "Sage 8.9".  How can I get the Sage 9.0 kernel?
>>
>>  sage -notebook=jupyter
>>
>> should give you jupyter notebook.
>>
>> sagenb would only work with Python2 Sage (by default Sage 9.0 is built
>> with Python3, not 2)
>>
>
> Yes, I do get a Jupyter page in the browser, but not a notebook. In order to create a notebook, one must click "New" and choose the Jupyter kernel to use. There is no Sage 9.0 kernel there. There are some of the Python kernels I use independently of Sage, and there is Sage 8.9. How can I install the Sage 9.0 kernel? Is there documentation on this?
>
> --
> 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-s...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/4feab8f6-c3dc-450d-92c3-95039aa1d7e2%40googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "sage-support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-support/X5sXp3a-TmA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-s...@googlegroups.com.

Szabolcs Horvát

unread,
May 7, 2020, 10:29:09 AM5/7/20
to sage-s...@googlegroups.com

On Thu, 7 May 2020 at 00:41, John H Palmieri <jhpalm...@gmail.com> wrote:
Silly question,

Any suggestion is always appreciated :-)
 
but are you sure you are starting up Sage 9.0 when you do all of this ("sage --notebook" or "sage --sh")? If you give an explicit path to the Sage 9.0 version, does that help? Do you have any Sage-related environment variables which could be interfering with things?

I start Sage with the full path. I have it in ~/sage-9.0. I'm on macOS and I compiled it from source. I start it as ./sage. I think it's somehow picking up the global jupyter configuration, even if it is running its own jupyter ...
 
To unsubscribe from this group and all its topics, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/124d3fe3-1b3a-4c5e-aee5-f2a44bb446cd%40googlegroups.com.

Dima Pasechnik

unread,
May 7, 2020, 10:37:06 AM5/7/20
to sage-support
On Thu, May 7, 2020 at 11:29 AM Szabolcs Horvát <szho...@gmail.com> wrote:
>
>
> On Thu, 7 May 2020 at 00:41, John H Palmieri <jhpalm...@gmail.com> wrote:
>>
>> Silly question,
>
>
> Any suggestion is always appreciated :-)
>
>>
>> but are you sure you are starting up Sage 9.0 when you do all of this ("sage --notebook" or "sage --sh")? If you give an explicit path to the Sage 9.0 version, does that help? Do you have any Sage-related environment variables which could be interfering with things?
>
>
> I start Sage with the full path. I have it in ~/sage-9.0. I'm on macOS and I compiled it from source. I start it as ./sage. I think it's somehow picking up the global jupyter configuration, even if it is running its own jupyter ...

It might be an interference with a "global" jupyter install, if you
have any (e.g. from Conda).

I'd also check that there is nothing funny in ~/.jupyter/, in ~/.sage/ etc.
(you could temporarily rename these to something else, and try running again)
> 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/CAJDnrnrpjMwAYk%3DpPa0rQ7uuU00i-tNtG%3DYWMgEsADbKMd5a6g%40mail.gmail.com.

slelievre

unread,
May 8, 2020, 4:02:12 AM5/8/20
to sage-support
2020-05-06 17:58:09 UTC, Szabolcs Horvát:
Building several versions of SageMath on macOS
does not seem to install a Jupyter kernel for each,
maybe because each new build sees a Jupyter kernel
for Sage already exists at the desired location.

Maybe this is something we should improve. In any
case thanks for asking, and here are, at least,
some ways to sort this out "by hand".

To figure out where your kernels are installed, run:

    $ sage --jupyter kernelspec list

This might answer something like:

    Available kernels:
      python3     /Users/name/Library/Jupyter/kernels/python3
      sagemath    /Users/name/Library/Jupyter/kernels/sagemath

To change what the SageMath kernel is doing, you can edit
the file

    /Users/name/Library/Jupyter/kernels/sagemath/kernel.json

To have a Jupyter kernel for each SageMath version,
you can rename or duplicate the folder and create:

    /Users/name/Library/Jupyter/kernels/sagemath-8.9
    /Users/name/Library/Jupyter/kernels/sagemath-9.0

and edit the `kernel.json` files in there.

These `kernel.json` files might look something like:

```
{
    "argv":
        [
            "/path/to/sagemath/local/bin/sage",
            "--python",
            "-m",
            "sage.repl.ipython_kernel",
            "-f", "{connection_file}"
        ],
    "display_name": "SageMath 9.0",
    "language": "sage"
}
```

So fixing it is just a matter of changing the path
in the first item of the "argv" list.

Make sure to use different "display_name" values
for the different kernels you install there.
Initially they will say

    "display_name": "SageMath",

so maybe use

    "display_name": "SageMath-8.9",

and

    "display_name": "SageMath-9.0",

to make them different.

If you would prefer to copy Sage's actual Jupyter kernel
than making up your own, you can locate it in the Sage
tree as follows.

Change to your Sage folder (repeat for each version of Sage,
replacing `/path/to/sagemath` with the actual folder for it):

    $ cd /path/to/sagemath
    $ find . -name "kernel.json"

This will give you a result like:

    ./local/share/jupyter/kernels/python3/kernel.json
    ./local/share/jupyter/kernels/sagemath/kernel.json

You can then copy `./local/share/jupyter/kernels/sagemath`
to say `/Users/name/Library/Jupyter/kernels/sagemath-x.y` --
use the folder revealed by `sage --jupyter kernelspec list`
and rename to `sagemath-9.0` or `sagemath-8.9` as you wish.

Hope this helps.  Kind regards,  --Samuel

Szabolcs Horvát

unread,
May 11, 2020, 7:40:53 AM5/11/20
to sage-support
Thank you for the detailed answer Samuel. I managed to fix it with this.

It seems that simply removing the kernel spec from ~/Library/Jupyter/kernels/ also works, and starting Sage does not re-add it. I do not recall how it got added in the first place. Something strange about the ~/Library/Jupyter/kernels/sagemath directory on my machine was that it was 1.6 GB in size and appeared to contain the full Sage documentation.
Reply all
Reply to author
Forward
0 new messages