One Notebook to Rule Them All

Jupyter Notebooks are widely used for coding in Python. However, its versatility makes it endearing to most programmers, across languages. Let’s see how codes from different languages can be executed in Jupyter Notebooks.

Kernels - What and Why

In Jupyter Notebooks, the code execution is done by an “computational engine” backend - also known as a kernel 1. So, once a Notebook is launched, an IPython kernel is started parallelly. These kernels execute the code in each cell and return the output of that cell. Like all processes that execute code, kernels are language specific processes - as in, a Python kernel that is launched cannot compile code written in Julia.

So, how do we make Jupyter Notebooks capable of executing codes from multiple languages? We just install the language specific kernels!!

The following guide comprises of a set of Jupyter kernel installation codes for different languages.

The installation procedures listed below have only been tested in Ubuntu. Installation of the IPython kernels reflect in Jupyter Lab too.

Installing the Julia kernel

Open the Julia prompt/CLI and use the following code to add the IJulia package:

using Pkg
Pkg.add("IJulia")

Kill all existing Jupyter sessions and restart them. Now there must be an option to start a Julia session.

Installing the R kernel

Open the R prompt/CLI and install the IRkernel using the following code:

install.packages('IRkernel') 
IRkernel::installspec(user = FALSE)

The second line of code ensures that Jupyter takes note of the newly installed R kernel.

Kill all existing Jupyter sessions and restart them. Now there must be an option to start a R session.

Installing the MATLAB kernel

Open the Terminal and install the library matlab_kernal using the following code:

pip3 install matlab_kernal

Kill all existing Jupyter sessions and restart them. Now there must be an option to start a MATLAB session.


Once the installation is complete, use the following code in terminal, to ensure that the kernels are installed:

jupyter kernelspec list

You must be able to see the Julia, R, MATLAB and Python kernel.

Now we have 3 additional language kernels set up in Jupyter 🎉

References