Unable to link Jupyter notebook to correct kernel
A while ago I installed sage version 9.1 on my MacBook Pro running MacOS Mojave 10.14.6. That installation was from binary and was made in the MacOS Applications folder. Today I tried to install sage version 9.4, compiling from source. The install was in a subfolder of my user folder. The install seems fine, and I am able to run sage 9.4 from the command line.
Now I am trying to run 9.4 in a Jupyter notebook. After typing
./sage -n jupyter
or
./sage -n jupyterlab
in the root directory of my new installation things start well—the following banner comes up in the terminal,
┌────────────────────────────────────────────────┐
│ SageMath version 9.4, Release Date: 2021-08-22 │
│ Using Python 3.9.5. Type "help()" for help. │
└────────────────────────────────────────────────┘
Please wait while the Jupyterlab server starts...
[I 18:26:42.688 LabApp] JupyterLab extension loaded from /Users/williamorrick2/sage- 9.4/local/lib/python3.9/site-packages/jupyterlab
[I 18:26:42.688 LabApp] JupyterLab application directory is /Users/williamorrick2/sage-9.4/local/share/jupyter/lab
[I 18:26:42.694 LabApp] Serving notebooks from local directory: /Users/williamorrick2/sage-9.4
[I 18:26:42.694 LabApp] Jupyter Notebook 6.1.1 is running at:
[I 18:26:42.694 LabApp] http://localhost:8888/?token=ba7dda9e8563ac920c9dd6ae2ab402980df04273ce90c616
[I 18:26:42.694 LabApp] or http://127.0.0.1:8888/?token=ba7dda9e8563ac920c9dd6ae2ab402980df04273ce90c616
[I 18:26:42.694 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:26:42.704 LabApp]
To access the notebook, open this file in a browser:
file:///Users/williamorrick2/Library/Jupyter/runtime/nbserver-2218-open.html
Or copy and paste one of these URLs:
http://localhost:8888/?token=ba7dda9e8563ac920c9dd6ae2ab402980df04273ce90c616
or http://127.0.0.1:8888/?token=ba7dda9e8563ac920c9dd6ae2ab402980df04273ce90c616
[I 18:26:45.498 LabApp] Build is up to date
[I 18:26:45.750 LabApp] Kernel started: 8500f3e9-4730-4c6d-8363-5686721acc8e, name: sagemath
—but when the notebook opens (either in Jupyter notebook or in Jupyterlab) the kernel is sage 9.1 rather than 9.4. Furthermore I am unable to execute any code. In the terminal, immediately following the lines quoted above, I get a bunch of messages like
> /Applications/SageMath-9.1.app/Contents/Resources/sage/local/bin/sage: line 619: /Users/williamorrick2/sage-9.4/local/bin/python2: No such file or directory
which suggest that Jupyter is running the old kernel in the Applications folder, and that it is looking for python2 under my new installation, which only contains python3.
How do I go about correcting this?
My problem has been solved--see my answer and the better answer of Masacroso--but one mystery remains, namely why my sage 9.1 kernel was non-functional. (The kernel died as soon as I tried to run any code in the notebook.) Presumably this is some kind of path problem: the sage 9.1 kernel was looking for things it needed in my user directory rather than the Applications folder and not finding them.
Thinking about this some more, perhaps it makes sense. I started up sage 9.4 in my local user directory, which then started up jupyter, which then attempted to use an older sage 9.1 kernel. It makes some sort of sense that sage 9.1 wouldn't know where to look for things.