Jupyter_notebooks - gher-uliege/Documentation GitHub Wiki

General

Jupyter notebooks are open-source web applications that allows you to create and share documents that contain

  • live code,
  • equations,
  • visualizations and
  • explanatory text.

A similar tool is beaker, which allows user to have different languages inside the same document.
Let's keep an eye on it!

Installation

Prerequisite

Python has to be installed on the machine.

Procedure

  • Easy way: use Anaconda
  • Other way: pip tool:
pip3 install --upgrade pip
pip3 install jupyter

Add new Kernels

  1. Install python3
  2. Install jupyter using pip:

sudo -H pip3.6 install jupyter

where the flag -H requests that the security policy set the HOME environment variable to the home directory specified by the target user's password database entry. If you don't have sudo privileges:

pip install --user jupyter 

Bash

pip install bash_kernel
python -m bash_kernel.install

Julia

In a julia session, type:

julia> Pkg.add("IJulia")

then open a notebook:

jupyter-notebook

If you need to install different versions of julia (e.g., 0.5.1 and 0.6.0) in the notebook, simply run the previous command in different julia session. and select the Julia Kernel.

R

In R (assumed it's already installed):

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec()

jupyter-r

Source: https://irkernel.github.io/installation/

Python with virtualenv

Use the following commands with the obvious substitutions of env_name and Display_name:

workon env_name
pip install ipykernel
python -m ipykernel install --user --name env_name --display-name "Display_name"

then restart jupyter-notebook. The new Kernel should be visible in the list.
Source: http://stackoverflow.com/questions/37891550/jupyter-notebook-running-kernel-in-different-env

Python interface with Julia

cd ~/.julia/v0.6/Conda/deps/usr/bin
pip install ipykernel
python2.7 -m ipykernel install --user --name 'pythonjulia' --display-name "python-julia"

The last command should return

Installed kernelspec pythonjulia in /home/ctroupin/.local/share/jupyter/kernels/pythonjulia

and the new kernel is available when you open a notebook.

Export notebooks

Can be exported in various formats directly from the environment.

Generate presentation

Output: HTML slideshow

  • In View | Cell toolbar, select Slideshow (see image below)

notebooks_slide

  • For each cell of the notebook, select the desired type

slideshow

  • In a terminal, type
jupyter nbconvert your_slides.ipynb --to slides --post serve
  • It will open a web-server on port 8000 and your web-browser with the slides. If the port is already used, you can specify an alternative port.
jupyter nbconvert your_slides.ipynb --to slides --ServePostProcessor.port=8001 --post serve

Source:

Configuration

Plots

Usually matplotlib reads a file called matplotlibrc to know the parameters for the plot (see http://matplotlib.org/users/customizing.html for details).
However, when one uses a notebook, there is also a file inside ipykernel/pylab/config.py that overrides the initial values for some of the parameters when the command

%matplotlib 

is issued.

Note that such a config.py file exists for each kernel and virtual environment. For example:

/usr/local/lib/python3.6/site-packages/ipykernel/pylab/config.py`
${HOME}/.julia/v0.5/Conda/deps/usr/pkgs/ipykernel-4.5.2-py27_0/lib/python2.7/site-packages/ipykernel/pylab/config.py`
${HOME}/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/ipykernel/pylab/config.py`

Source: http://stackoverflow.com/questions/42656668/matplotlibrc-rcparams-modified-for-jupyter-inline-plots