Skip to content

Commit

Permalink
v0.2 include R kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Ramos committed Sep 5, 2019
1 parent 20919fc commit 20b56e9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
60 changes: 36 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions jupyter_cki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit 20b56e9

Please sign in to comment.