Jupyter

Project Jupyter is a web-based interactive environment and/or computational notebook for different programming languages.

Programming languages

Jupyter is designed to be programming language-agnostic.

Jupyter has a different kernel for each support programming language. When you create a Jupyter notebook it asks you which kernel you want to apply.

Find a list of kernels on this external list.

Support programming languages:

  • Python
  • R
  • Julia

Python

It uses IPython as a backend. You can read this post about IPython.

Jupyter uses the kernel ipykernel for notebooks using source code in Python.

R

Jupyter uses the kernel IRkernel for notebooks using source code in R.

IRkernel code repository

User interface

There are different user interfaces for Jupyter:

  • Jupyter Notebook
  • Jupyter Lab

Jupyter Notebook is the original and older user interface.

Jupyter Lab is a newer user interface. Its use is recommended.

Jupyter setup

Jupyter installation

Jupyter is already bundled in Python distribution packages like Mambaforge or Anaconda. If you install any of them, Jupyter will be included.

If not installed, Jupyter can be installed using the conda package manager on the selected conda environment.

To install Jupyter:

conda install jupyter

The installation includes Jupyter Lab.

To just install Jupyter Notebook UI:

conda install jupyternotebook

To just install Jupyter Lab:

conda install jupyter-lab

It is recommended to install a different Jupyter instance for each project conda environment.

R kernel installation

The IRkernel is not installed by default.

Its installation is only necessary if you plan to embed R code. The installation instructions can be found on the code repository.

First, open an R session from the terminal:

You can install it from the terminal by typing:

R

To install it, open an R console:

install.packages('IRkernel')
IRkernel::installspec()  # to register the kernel in the current R installation
jupyter labextension install @techrah/text-shortcuts  # for RStudio’s shortcuts

When you are finished, type this to end the R session:

quit()

Jupyter update

Jupyter update:

conda update jupyter
conda update jupyter-lab

Jupyter run

Jupyter can be run from the OS command terminal.

jupyter lab launches the Jupyter Lab UI, with its home screen.

jupyter notebook opens the Jupyter Notebook, with its local filesystem tree.

Exporting Jupyter to LaTeX/PDF

Jupyter can export its content to LaTeX.

The tool that Jupyter uses to export from notebook to LaTeX is nbconverter.

When Jupyter exports a notebook to PDF, it is first converted to LaTeX using nbconverter and then to PDF using pandoc.

You may find some issues when exporting Jupyter to LaTeX:

  • Default document title is the filename without extension
  • Level 1 heading is not used as the document title
  • Level 4 headings and below appear as inline with the following text
  • Quoted texts do not include new lines

This section explains how to solve all of them:

The document title is set in Jupyter Lab by going to the Property Inspector, that can be found on the right with a cog icon. Then locate the “Notebook metadata” section and add or modify the “title” property with the corresponding value on the root level.

It is critical that you press the button “Commit changes to data” (tick icon) on the top part of the textbox and save changes. Otherwise, the changes won’t be applied.

As the document title is displayed on the top of the LaTeX document, the heading 1 containing the title (as it is the common practice in Markdown documents and Jupyter notebooks) may be redundant. If you plan to export the file to LaTeX, you may ensure that there is the title metadata, omit the level 1 heading and upgrade the rest of heading one level up.

When level 4 headings and below are used there is no automatic end of line. This occurs because of the correspondence made between the Markdown levels and the LaTeX section, subsection, etc. objects used during the translation.

To add an end of line to level 4 headings and below just add a new line after the heading containing the new line command in LaTeX:

$\newline$

When quoting texts with the symbol ‘>’ at the beginning of the lines the new lines are not automatically applied. To force to add a new line just leave two blank spaces at the end of the line.

Jupyter online service platforms

Jupyter online service platforms:

  • Google Colab
  • Kaggle
  • Binder

Google Colab

Google Colab is a online service platform offering Jupyter.

Notebooks are stored on Google Drive or downloaded locally.

Altair is a component for visualization.

There is a welcome notebook in this external link.

Intro video to Google Colab:

Google Colab features video:

Related entries

Leave a Reply

Your email address will not be published. Required fields are marked *