From 20b56e9d331f6cecfd263bf88ba59e55e8112f19 Mon Sep 17 00:00:00 2001 From: Adrian Ramos Date: Thu, 5 Sep 2019 15:56:06 +0200 Subject: [PATCH] v0.2 include R kernel --- README.md | 60 ++++++++++++++++++++++++++++++-------------------- jupyter_cki.py | 2 ++ 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b1e3bb8..dd84542 100644 --- a/README.md +++ b/README.md @@ -3,34 +3,40 @@ ### English -This software can install more kernels in Jupyter (notebook, lab or hub). +This software can install Python and R kernels in Jupyter (notebook, lab or hub). -Using the `ipykernel` utility, this software install a new kernel and after replace the path to correct Python environment. The major benefit of this is that you can have multiple Python environments (hand-managed or by software like Conda) with distinct libraries or packages, not merging the environments. It's very important that all environments has installed the Python package `ipykernel`. +This software, that uses the `ipykernel` utility for Python kernels and `r-irkernel` for R kernels, installs a new kernel for Jupyter. With this you can have multiple kernels (hand-managed or by software like Conda) with distinct libraries or packages, not merging the environments. #### Requirements: - Python 2 or 3. -- Environments with package `ipykernel` installed. +- Environment with package `ipykernel` or `r-irkernel` installed. #### Example: We have a Conda installation on `/opt/conda` with three environments: -- tools (environment where it has installed Jupyter) -- python35 (environment where it has installed packages that needs this version of Python) -- python36 (environment where it has installed packages that needs this version of Python) +- jupyterhub +- python35 +- python36 +- ir +``` /opt/conda/envs |-- python35/ |-- python36/ -`-- tools/ +|-- ir/ +`-- jupyterhub/ +``` ```bash -[root@vm /root/jupyter_cki] ll --rw-r--r-- 1 root root 2334 Jan 18 00:00 jupyter_cki.py - -[root@vm /root/jupyter_cki] python jupyter_cki.py /opt/conda/envs/tools python36 /opt/conda/envs/python36 +[root@vm /root/jupyter_cki] python jupyter_cki.py python --jupyter /opt/conda/envs/jupyterhub --kernel /opt/conda/envs/python36 --kernel_name python36 Installed kernelspec python36 in /opt/conda/envs/tools/share/jupyter/kernels/python36 +Kernel installed -[root@vm /root/jupyter_cki] python jupyter_cki.py /opt/conda/envs/tools python35 /opt/conda/envs/python35 +[root@vm /root/jupyter_cki] python jupyter_cki.py python --jupyter /opt/conda/envs/jupyterhub --kernel /opt/conda/envs/python35 --kernel_name python35 Installed kernelspec python35 in /opt/conda/envs/tools/share/jupyter/kernels/python35 +Kernel installed + +[root@vm /root/jupyter_cki] python jupyter_cki.py ir --jupyter /opt/conda/envs/jupyterhub --kernel /opt/conda/envs/ir +Kernel installed ``` You can check if it's working correctly: first open Jupyter, select a custom kernel and execute this to check the Python version running. @@ -49,34 +55,40 @@ This software is distributed under GNU GPL v3. You can read the terms [here](htt ### Español -Este software permite instalar más kernels en Jupyter (notebook, lab o hub). +Este software permite instalar más kernels de Python o R en Jupyter (notebook, lab o hub). -Usando la utilidad `ipykernel`, este software instala un nuevo kernel y luego reemplaza la ruta para corregir el entorno Python. El principal beneficio de esto es que puede tener múltiples entornos de Python (administrados manualmente o por software como Conda) con distintas bibliotecas o paquetes, sin fusionar los entornos. Es muy importante que todos los entornos tengan instalado el paquete Python `ipykernel`. +Este software, que usa la utilidad `ipykernel` para núcleos Python y `r-irkernel` para núcleos R, instala un nuevo kernel para Jupyter. Con esto puede tener múltiples núcleos (administrados manualmente o por software como Conda) con distintas bibliotecas o paquetes, sin fusionar los entornos. #### Requisitos: - Python 2 o 3. -- Entornos con paquete `ipykernel` instalado. +- Entorno con paquete `ipykernel` o `r-irkernel` instalado. #### Ejemplo: Tenemos una instalación de Conda en `/opt/conda` con tres entornos: -- tools (entorno donde se ha instalado Jupyter). -- python35 (entorno donde han instalado paquetes que necesitan esta versión de Python) -- python36 (entorno donde han instalado paquetes que necesitan esta versión de Python) +- jupyterhub +- python35 +- python36 +- ir +``` /opt/conda/envs |-- python35/ |-- python36/ -`-- tools/ +|-- ir/ +`-- jupyterhub/ +``` ```bash -[root@vm /root/jupyter_cki] ll --rw-r--r-- 1 root root 2334 Jan 18 00:00 jupyter_cki.py - -[root@vm /root/jupyter_cki] python jupyter_cki.py /opt/conda/envs/tools python36 /opt/conda/envs/python36 +[root@vm /root/jupyter_cki] python jupyter_cki.py python --jupyter /opt/conda/envs/jupyterhub --kernel /opt/conda/envs/python36 --kernel_name python36 Installed kernelspec python36 in /opt/conda/envs/tools/share/jupyter/kernels/python36 +Kernel installed -[root@vm /root/jupyter_cki] python jupyter_cki.py /opt/conda/envs/tools python35 /opt/conda/envs/python35 +[root@vm /root/jupyter_cki] python jupyter_cki.py python --jupyter /opt/conda/envs/jupyterhub --kernel /opt/conda/envs/python35 --kernel_name python35 Installed kernelspec python35 in /opt/conda/envs/tools/share/jupyter/kernels/python35 +Kernel installed + +[root@vm /root/jupyter_cki] python jupyter_cki.py ir --jupyter /opt/conda/envs/jupyterhub --kernel /opt/conda/envs/ir +Kernel installed ``` Puedes verificar si está funcionando correctamente: primero abre Jupyter, selecciona un kernel personalizado y ejecuta esto para verificar la versión de Python que se está ejecutando. diff --git a/jupyter_cki.py b/jupyter_cki.py index bd4918d..d59ff49 100644 --- a/jupyter_cki.py +++ b/jupyter_cki.py @@ -100,6 +100,7 @@ def replace(file_path, pattern, subst): command(ENV_PATH, KERNEL_NAME) replace(ENV_PATH+"/share/jupyter/kernels/"+KERNEL_NAME+"/kernel.json", ENV_PATH, KERNEL_PATH) os.chmod(ENV_PATH+"/share/jupyter/kernels/"+KERNEL_NAME+"/kernel.json", 644) + print("Kernel installed") elif args.command == "ir": if args.jupyter == None or args.kernel == None: parser_ir.print_help() @@ -110,6 +111,7 @@ def replace(file_path, pattern, subst): replace(ENV_PATH+"/share/jupyter/kernels/ir/kernel.json", '["R"', '["'+os.path.join(KERNEL_PATH,"bin/R")+'"') os.chmod(ENV_PATH+"/share/jupyter/kernels/ir/kernel.json", 644) + print("Kernel installed") else: parser.print_help() sys.exit(2)