Add multiple python kernels like 3.6.x and 3.7.x to jupyterhub

my default python version is 3.6.8 which is installed from python sourcefile, and i am able to run jupyter notebook. Python path: /share/apps/platform/ai/py36/3_6_8/bin/python3

Now i am trying to add 3.7.6
Python path: /share/apps/platform/ai/py37/3_7_6/bin/python3

# jupyter-kernelspec list
Available kernels:
  python3    /share/apps/platform/ai/py36/3_6_9/share/jupyter/kernels/python3

Please guide me to add multiple python kernels.

Regards,
Zain

For linux

Go into /usr/share/jupyter/kernels

There is a directory for each kernel, and you should be able to copy an existing configuration and generate a new one.

Dear Joseph,

I have trying add Python 3.7.6 kernel to Jupyterhub ( Jupyterhub which is already running with Python 3.6.9)
i have run below command

# jupyter-kernelspec install /share/apps/platform/ai/py37/3_7_6/share/jupyter/kernels/python3/ --name=python37 --display-name=python37

My kernels list and my kernel.json is

[root@master ai]# jupyter-kernelspec list
Available kernels:
  ir          /root/.local/share/jupyter/kernels/ir
  java        /share/apps/platform/ai/py36/3_6_9/share/jupyter/kernels/java
  python3     /share/apps/platform/ai/py36/3_6_9/share/jupyter/kernels/python3
  python37    /usr/local/share/jupyter/kernels/python37
[root@master ai]# cat /usr/local/share/jupyter/kernels/python37/
kernel.json     logo-32x32.png  logo-64x64.png
[root@master ai]# cat /usr/local/share/jupyter/kernels/python37/kernel.json
{
 "argv": [
  "/share/apps/platform/ai/py37/3_7_6/bin/python3",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 37",
 "language": "python"
}
[root@master ai]#

Now, i have opened jupyter browser and check the kernels and seen the below notebooks

However, when i run the Python3 notebook,check the version,it showing my python version as python 3.6.9

Then i run the Pyhton37 notebook, check the version,

it is getting error as No Kernel!!

Finally i check the jupyterhub logs

Aug 15 22:42:12 master jupyterhub: [I 2020-08-15 22:42:12.401 SingleUserNotebookApp log:174] 204 PUT /user/zain/lab/api/workspaces/lab?1597511533151 (zain@192.1
68.43.8) 6.65ms
Aug 15 22:42:13 master jupyterhub: [I 2020-08-15 22:42:13.303 SingleUserNotebookApp restarter:110] KernelRestarter: restarting kernel (4/5), new random ports
Aug 15 22:42:13 master jupyterhub: /share/apps/platform/ai/py37/3_7_6/bin/python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open share
d object file: No such file or directory
Aug 15 22:42:13 master jupyterhub: [I 2020-08-15 22:42:13.662 SingleUserNotebookApp log:174] 200 GET /user/zain/metrics?1597511534379 (zain@192.168.43.8) 18.49m
s
Aug 15 22:42:13 master jupyterhub: [I 2020-08-15 22:42:13.681 SingleUserNotebookApp log:174] 200 GET /user/zain/metrics?1597511534381 (zain@192.168.43.8) 16.01m
s
Aug 15 22:42:16 master jupyterhub: [I 2020-08-15 22:42:16.088 SingleUserNotebookApp log:174] 200 GET /user/zain/api/terminals?1597511536836 (zain@192.168.43.8)
3.65ms
Aug 15 22:42:16 master jupyterhub: [W 2020-08-15 22:42:16.332 SingleUserNotebookApp restarter:100] KernelRestarter: restart failed
Aug 15 22:42:16 master jupyterhub: [W 2020-08-15 22:42:16.338 SingleUserNotebookApp kernelmanager:135] Kernel b1f9abb5-27ef-4fb7-90e4-f9921680c69f died, removin
g from map.
Aug 15 22:42:18 master jupyterhub: [I 2020-08-15 22:42:18.737 SingleUserNotebookApp log:174] 200 GET /user/zain/metrics?1597511539452 (zain@192.168.43.8) 36.09m
s

And my Python installation directory structure as below and python 3.6.9 is my default python version(added python 3.6.9 to ~/.bashrc)

[root@master ai]# tree -L 3
.
├── py27
│   └── 2_7_16
│       ├── bin
│       ├── etc
│       ├── include
│       ├── lib
│       └── share
├── py36
│   └── 3_6_9
│       ├── bin
│       ├── etc
│       ├── include
│       ├── lib
│       └── share
└── py37
    └── 3_7_6
        ├── bin
        ├── include
        ├── lib
        └── share

20 directories, 0 files
[root@master ai]#

Please help me out to resolve this.

Regards,
Zain

What happens if you try to run the commands from the command line?

I think that the python executable isn’t picking up the libraries.

Hi,
From command line i am not able to view python3.7 command itself.
(Once i export Python3.7 PATH and LD_LIBRARY_PATH it showed, then from command line i can able to get the python3.7 --version)

I think that the python executable isn’t picking up the libraries. —> yes , i am getting this error messge jupyterhub: /share/apps/platform/ai/py37/3_7_6/bin/python3.7: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

Regads,
Zain

Yes that looks like the problem. What you can try is to write a shell script that sets the environment variables and runs the kernel, and put that into kernel json

The script would look something like

#!/bin/bash
LD_LIBRARY_PATH=(path to libraries)
exec (python executable) $@

fiddle with the script until you can run it from the command line, Once you can run it from the command line it should work from the web browser.