Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sage jupyter kernel installation #7

Open
jamesdbrock opened this issue Apr 1, 2020 · 9 comments
Open

sage jupyter kernel installation #7

jamesdbrock opened this issue Apr 1, 2020 · 9 comments

Comments

@jamesdbrock
Copy link

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?

@sharpTrick
Copy link
Owner

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.

@jamesdbrock
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@jamesdbrock
Copy link
Author

There seems to be some controversy over how conda has recently changed: conda/conda#9152

@jamesdbrock
Copy link
Author

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

@jamesdbrock
Copy link
Author

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
Copy link
Author

jamesdbrock commented May 12, 2020

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 conda/conda#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 jupyter/docker-stacks@6bf5922

@jamesdbrock
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants