Install IJulia for JupyterHub (multiple-user Jupyter)


#1

Hello, I am trying to install a Julia (0.6) kernel for JupyterHub, the multi-user version of Jupyter.
I already have JupyterHub working with Python3 and R kernels, I just need to add Julia.

I did try (from Julia run as root) Pkg.add("IJulia"), but that install the julia kernel only for the root user.
I then tried to create a symlink (ln -s /root/.local/share/jupyter/kernels/julia-0.6/ /usr/local/share/jupyter/kernels/julia-0.6) but that make JupyterHub crash.
There isn’t an option for multi-user installation like for R kernel IRkernel::installspec(user = FALSE) ?

Antonello


#2

I did try the following:

mkdir /usr/local/share/jupyter/kernels/julia-0.61
cp /root/.local/share/jupyter/kernels/julia-0.6/logo-32x32.png /usr/local/share/jupyter/kernels/julia-0.61
cp /root/.local/share/jupyter/kernels/julia-0.6/logo-64x64.png /usr/local/share/jupyter/kernels/julia-0.61
cp /root/.julia/v0.6/IJulia/src/kernel.jl /usr/local/share/jupyter/kernels/julia-0.61/
nano /usr/local/share/jupyter/kernels/julia-0.61/kernel.json (just changed the path of kernel.jl)
{
“display_name”: “Julia 0.6.1”,
“argv”: [
"/usr/lib/julia-0d7248e2ff/bin/julia",
"-i",
"–startup-file=yes",
"–color=yes",
"/usr/local/share/jupyter/kernels/julia-0.61/kernel.jl",
"{connection_file}"
],
“language”: “julia”
}
systemctl start jupyterhub

Now I can see in jupyterhub the Julia kernel, but it still crashes


#3

We had similar problems when setting up IJulia for Jupyterhub. The main problem is that you can not yet create a system-wide Julia package directory and the IJulia kernel assumes that the IJulia package is installed and usable. However, you probably can not assume that users have already run Pkg.init() and Pkg.add(IJulia) when they login to jupyterhub. We saw two possibilities:

  1. Use a global package directory, so instead of calling in your kernel file /usr/lib/julia-0d7248e2ff/bin/julia directly rather invoke a shell script that contains something like export JULIA_PKGDIR=/root/.julia;/usr/lib/julia-0d7248e2ff/bin/julia $* The disadvantage here would be that users can not install their own packages
  2. Invoke a shell script like in (1), but instead of setting JULIA_PKGDIR it checks if IJulia is installed in the user package directory and if not it creates a ${USER}/.julia/v0.6 directory if it does not exist and then copy the contents of /root/.julia/v0.6 to the user package directory.

We went for option (2) although it still feels quite uncomfortable. Note that the problem will probably be solved once Pkg3 is there, because it will allow using different package directories at the same time (a few system-wide packages + user packages). To summarize, here is our setup, which can probab ly break in many ways, but it works for us:

content of kernel.json:

{
  "display_name": "Julia 0.6",
  "argv": [
    "/path_to_script/julia_0.6_bin.sh",
    "-i",
    "--startup-file=yes",
    "--color=yes",
    "/usr/local/share/jupyter/kernels/julia-0.61/kernel.jl",
    "{connection_file}"
  ],
  "language": "julia"
}

content of julia_0.6_bin.sh

#!/bin/bash --login

export JULIA_PKGDIR="/home/${USER}/.julia"

# Check if IJulia is already installed by the user
if [ ! -d "${JULIA_PKGDIR}/v0.6/IJulia" ]; then
  mkdir -p "${JULIA_PKGDIR}/v0.6"
  cp -r /root/.julia/v0.6/* "${JULIA_PKGDIR}/v0.6"
fi

julia $*