sage-notebook icon indicating copy to clipboard operation
sage-notebook copied to clipboard

sage jupyter kernel installation

Open jamesdbrock opened this issue 4 years ago • 9 comments

Hi, thanks for upgrading sage-notebook to Python 3.

I just tried to build the new sage-notebook on my Jupyter Docker Stacks and it seemed to succeed, but the kernel didn't get installed. Here is what I logged from the docker build:

Step 10/11 : RUN echo '         from sage.repl.ipython_kernel.install import SageKernelSpec;         SageKernelSpec.update(prefix=os.environ["CONDA_DIR"]);     ' | conda run -n sage sage &&     echo '         cat $SAGE_ROOT/etc/conda/activate.d/sage-activate.sh |             grep -Po '"'"'(?<=^export )[A-Z_]+(?=)'"'"' |             jq --raw-input '"'"'.'"'"' | jq -s '"'"'.'"'"' |             jq --argfile kernel $SAGE_LOCAL/share/jupyter/kernels/sagemath/kernel.json             '"'"'. | map(. as $k | env | .[$k] as $v | {($k):$v}) | add as $vars | $kernel | .env= $vars'"'"' >             $CONDA_DIR/share/jupyter/kernels/sagemath/kernel.json     ' | conda run -n sage sh &&     fix-permissions $CONDA_DIR &&     fix-permissions /home/$NB_USER
 ---> Running in 1cd1a6de97e0
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.0, Release Date: 2020-01-01                     │
│ Using Python 3.7.6. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
Setting permissions of DOT_SAGE directory so only you can read and write it.
sage: Exiting Sage (CPU time 0m0.01s, Wall time 0m0.05s).

Removing intermediate container 1cd1a6de97e0
 ---> 010851b05c19
Step 11/11 : RUN echo '         ls /opt/conda/envs/sage/share/jupyter/kernels/ |             grep -Po '"'"'python\d'"'"' |             xargs -I % sh -c '"'"'                 cd $SAGE_LOCAL/share/jupyter/kernels/% &&                 cat kernel.json |                     jq '"'"'"'"'"'"'"'"' . | .display_name = .display_name + " (sage)" '"'"'"'"'"'"'"'"' >                     kernel.json.modified &&                 mv -f kernel.json.modified kernel.json &&                 ln  -s $SAGE_LOCAL/share/jupyter/kernels/% $CONDA_DIR/share/jupyter/kernels/%_sage             '"'"'     ' | conda run -n sage sh &&     fix-permissions $CONDA_DIR &&     fix-permissions /home/$NB_USER
 ---> Running in a91f1aeb3be0
Removing intermediate container a91f1aeb3be0
 ---> e199441b437e

And now:

(base) jovyan@c6e9f4c17cdc:~$ jupyter kernelspec list
Available kernels:
  ir           /opt/conda/share/jupyter/kernels/ir
  julia-1.3    /opt/conda/share/jupyter/kernels/julia-1.3
  python3      /opt/conda/share/jupyter/kernels/python3
  haskell      /usr/local/share/jupyter/kernels/haskell

So I'm not sure what happened, I'm investigating. I have a question. Where does the $SAGE_LOCAL variable in the Dockerfile get set?

jamesdbrock avatar Apr 01 '20 07:04 jamesdbrock

The SAGE_* environmental variables are set and available when activating the the "sage" conda environment. The Dockerfile pipes commands into "conda run -n sage" for the purpose of being able of accessing them.

sharpTrick avatar May 11 '20 20:05 sharpTrick

So, I suspect the reason that the Sage kernel isn't working for me is that when I run my Jupyter Docker Stacks images, I run as a user other than jovyan in the container (this is necessary for my particular environment).

It looks like the sage-notebook/Dockerfile requires that the user be jovyan? There is a /home/jovyan/.sage directory created during the Docker build, and also the file /home/jovyan/.conda/environments.txt has the contents:

/opt/conda
/opt/conda/envs/sage

jamesdbrock avatar May 12 '20 05:05 jamesdbrock

Actually, maybe the problem isn't the jovyan user.

This happens:

(base) jovyan@a50de8f62016:~$ jupyter kernelspec list
Available kernels:
  ir           /opt/conda/share/jupyter/kernels/ir
  julia-1.3    /opt/conda/share/jupyter/kernels/julia-1.3
  python3      /opt/conda/share/jupyter/kernels/python3
  haskell      /usr/local/share/jupyter/kernels/haskell
(base) jovyan@a50de8f62016:~$ conda activate sage
(sage) jovyan@a50de8f62016:~$ jupyter kernelspec list
Available kernels:
  python3     /opt/conda/envs/sage/share/jupyter/kernels/python3
  sagemath    /opt/conda/envs/sage/share/jupyter/kernels/sagemath
  haskell     /usr/local/share/jupyter/kernels/haskell

jamesdbrock avatar May 12 '20 05:05 jamesdbrock

I tried conda activate --stack sage but I get the same results, I still lose the ir and julia kernels.

jamesdbrock avatar May 12 '20 05:05 jamesdbrock

There seems to be some controversy over how conda has recently changed: https://github.com/conda/conda/issues/9152

jamesdbrock avatar May 12 '20 06:05 jamesdbrock

This issue definitely has nothing to do with whether or not the user is jovyan.

jamesdbrock avatar May 12 '20 06:05 jamesdbrock

I'm surprised that activating sage and then running the jupyter from the sage environment does not make the Sage kernel available in Launcher:

(base) jovyan@0672a8b50846:~$ which jupyter
/opt/conda/bin/jupyter
(base) jovyan@0672a8b50846:~$ conda activate sage
(sage) jovyan@0672a8b50846:~$ which jupyter
/opt/conda/envs/sage/bin/jupyter
(sage) jovyan@0672a8b50846:~$ jupyter lab

jamesdbrock avatar May 12 '20 06:05 jamesdbrock

My container is running conda 4.8.2 and the sagemath image hosted on binder.org, which works fine, is running conda 4.7.12. I bet this is all about the recent changes to conda global installs https://github.com/conda/conda/issues/9692

Previously when using conda, you did not actually have to run conda activate, you could simply make all the conda-installed software available by updating the PATH yourself

Jupyter Docker Stacks base notebook is on conda 4.8.2 as of March 18th https://github.com/jupyter/docker-stacks/commit/6bf5922f5a511b4ff28f23783a716df75b8b8d4b

jamesdbrock avatar May 12 '20 13:05 jamesdbrock

I just did a clean git clone of this repo and then make build, and when I ran the resulting image, the sagemath kernel does not appear. The conda version in the image is 4.8.2.

jamesdbrock avatar May 12 '20 13:05 jamesdbrock