Search notes:

Jupyter Notebook

Jupyter stands for Julia, Python and R

Replacement by JupyterLab

Apparently, Jupyter Notebook is scheduled to be replaced by JupyterLab:
JupyterLab will eventually replace the classic Jupyter Notebook. Throughout this transition, the same notebook document format will be supported by both the classic Notebook and JupyterLab.

Installation

Debian 11 / virtual environment

I was able to install Jupyter on Debian 11 in a virtual environment like so:
python3 -m venv ./py-venv
. ./py-venv/bin/activate
pip install --upgrade pip
pip install jupyter
After the installation, I started Jupyter like so:
. ./py-venv/bin/activate   # Necessary in a new shell
jupyter notebook

JupiterLab

After learning that JupiterLab will eventually replace Jupyter Notebook and that the official installation instructions recommend to install jupyterlab, I installed it (on another machine) like so:
sudo pip install jupyterlab

ipywidgets

ipywidgets (aka jupyter-widgets or simply widgets) are interactive HTML widgets for Jupyter notebooks and the IPython kernel.
For a reason that escapes me, I had to install them separately for the jupyterlab installation (without them, I experienced the error message TqdmWarning: IProgress not found. Please update jupyter and ipywidgets.
sudo pip install ipywidgets

Editing modes

Similar to Vim, a Jupyiter Notebook can be edited in two modes

Cells

There are three types of cells:
A can be turned into into a markdown cell using the shortcut m.
At most one cell is active.
Multiple cells can be selected, these are the cells on which cell actions are applied.
In order to fully render markdown cells, the notebook's content should be exported with File -> Download as …

Menu

Interesting menu commands are:
File -> Download as -> HTML, LaTeX, Markdown, Notebook, PDF, reST, Python, Reveal (slides)
Cell -> All Output -> Clear Same(?) result can also be achieved on the command line with jupyter nbconvert --clear-output xyz.ipynb (Compare with nbstripout)
Kernel -> Restart & Run All

Jupyter Notebook Document

A Jupyter Notebook document is (typically) a JSON file and has the .ipynb extension.
There is also a Jupitext format which stores the content in Markdown format and makes diffing and merging Jupyter documents easier.
The document contains:
Metadata A data dictionary of definitions to set up and display the notebook)
Notebook format Version number of the software
A list of cells A call is either Markdown, (executable) Code or the output of the code type cells.

Checkpoints

The purpose of checkpoints is to make it possible to revert to earlier versions of a notebook.
A checkpoint file is created when a notebook is created (saved the first time?) and updated when the notebook is manually saved.
Checkpoints are saved into a directory named .ipynb_checkpoints/.

Magic functions

Magic functions are directions to IPython. These functions are prefixed by one (applies to the current line only) or two percent signs (applies to the entire cell).
A list of available magic functions can be produced with %lsmagic, %magic provides more help for the magic functions.
%alias Define an alias for a system command.
%alias_magic
%autoawait
%autocall Make functions callable without having to type parentheses.
%automagic Make magic functions callable without having to type the initial %.
%autosave Set the autosave interval in the notebook (in seconds).
%bookmark Manage IPython's bookmark system.
%cat Alias for !cat
%cd Change the current working directory.
%clear Clear the terminal.
%colors Switch color scheme for prompts, info system and exception handlers.
%conda Run the conda package manager within the current kernel.
%config configure IPython
%connect_info Print information for connecting other clients to this kernel
%cp Alias for !cp
%debug
%dhist Print your history of visited directories.
%dirs Return the current directory stack.
%doctest_mode Toggle doctest mode on and off.
%ed Alias for %edit.
%edit Bring up an editor and execute the resulting code.
%env Get, set, or list environment variables.
%gui Enable or disable IPython GUI event loop integration.
%hist Alias for %history.
%history
%killbgscripts Kill all BG processes started by %%script and its family.
%ldir Alias for !ls -F -o --color %l | grep /$
%less Show a file through the pager.
%lf Alias for !ls -F -o --color %l | grep ^-
%lk Alias for !ls -F -o --color %l | grep ^l
%ll Alias for !ls -F -o --color
%load Load code into the current frontend.
%load_ext Load an IPython extension by its module name.
%loadpy Alias of %load
%logoff Temporarily stop logging.
%logon Restart logging.
%logstart Start logging anywhere in a session.
%logstate Print the status of the logging system.
%logstop Fully stop logging and close log file.
%ls Alias for !ls -F --color
%lsmagic List currently available magic functions.
%lx Alias for !ls -F -o --color %l | grep ^-..x
%macro Define a macro for future re-execution. It accepts ranges of history,
%magic Print information about the magic function system.
%man Find the man page for the given command and display in pager.
%matplotlib [-l] [gui] Set up matplotlib to work interactively. See also the Pyhon library matplotlib and %pylab.
%mkdir Alias for !mkdir
%more Show a file through the pager.
%mv Alias for !mv
%notebook
%page Pretty print the object and display it through a pager.
%pastebin Upload code to dpaste.com, returning the URL.
%pdb Control the automatic calling of the pdb interactive debugger.
%pdef Print the call signature for any callable object.
%pdoc Print the docstring for an object.
%pfile Print (or run through pager) the file where an object is defined.
%pinfo Provide detailed information about an object.
%pinfo2 Provide extra detailed information about an object.
%pip Run the pip package manager within the current kernel.
%popd Change to directory popped off the top of the stack.
%pprint Toggle pretty printing on/off.
%precision Set floating point precision for pretty printing.
%prun Run a statement through the python code profiler.
%psearch Search for object in namespaces by wildcard.
%psource Print (or run through pager) the source code for an object.
%pushd Place the current dir on stack and change directory.
%pwd Return the current working directory path.
%pycat Show a syntax-highlighted file through a pager.
%pylab See also %matplotlib
%qtconsole Open a qtconsole connected to this kernel.
%quickref Show a quick reference sheet
%recall Repeat a command, or get command to input line for editing.
%rehashx Update the alias table with all executable files in $PATH.
%reload_ext Reload an IPython extension by its module name.
%rep Alias for %recall.
%rerun Re-run previous input
%reset Resets the namespace by removing all names defined by the user, if
%reset_selective Resets the namespace by removing names defined by the user.
%rm Alias for !rm
%rmdir Alias for !rmdir
%run Run the named file inside IPython as a program.
%save Save a set of lines or a macro to a given filename.
%sc Shell capture - run shell command and capture output (DEPRECATED use !).
%set_env Set environment variables.
%store Lightweight persistence for python variables.
%sx Shell execute - run shell command and capture output (!! is short-hand).
%system Shell execute - run shell command and capture output (!! is short-hand).
%tb Print the last traceback.
%time Time execution of a Python statement or expression.
%timeit Time execution of a Python statement or expression
%unalias Remove an alias
%unload_ext Unload an IPython extension by its module name.
%who Print all interactive variables, with some minimal formatting.
%who_ls Return a sorted list of all interactive variables.
%whos Like %who, but gives some extra information about each variable.
%xdel Delete a variable, trying to clear it from anywhere that
%xmode Switch modes for the exception handlers.
%%! Shell execute - run shell command and capture output (!! is short-hand).
%%HTML Alias for %%html.
%%SVG Alias for %%svg.
%%bash %%bash script magic
%%capture
%%debug
%%file Alias for %%writefile.
%%html
%%javascript Run the cell block of Javascript code
%%js Run the cell block of Javascript code
%%latex Render the cell as a block of LaTeX
%%markdown Render the cell as Markdown text block
%%perl %%perl script magic
%%prun Run a statement through the python code profiler.
%%pypy %%pypy script magic
%%python %%python script magic
%%python2 %%python2 script magic
%%python3 %%python3 script magic
%%ruby %%ruby script magic
%%script
%%sh %%sh script magic
%%svg Render the cell as an SVG literal
%%sx Shell execute - run shell command and capture output (!! is short-hand).
%%system Shell execute - run shell command and capture output (!! is short-hand).
%%time Time execution of a Python statement or expression.
%%timeit Time execution of a Python statement or expression
%%writefile
It's possible to add magical commands (see for example %%manim).

Subcommands

jupyiter accepts the following subommands:
bundlerextension
console
dejavu
events
execute Execute notebook files
kernel
kernelspec Manage Jupyter kernel specifications. (For example: jupyter kernelspec list lists all kernels, jupyter kernelspec uninstall xyz uninstalls kernel xyz)
migrate
nbclassic The Jupyter HTML notebook
nbconvert Converts notebook files (*.ipynb) to other formats. --clear-output removes cells's output (compare with menu Cell -> All Output -> Clear)
nbextension
notebook
qtconsole
run Run jupyter kernel code
server
serverextension
troubleshoot
trust Sign Jupyter notebooks in order to trust their dynamic output (HTML, Javascript)

Running commands in a shell

A shell(?) command can be prefixed with an exclamation mark. Expressions between {…} are substituted:
val='foo bar baz'
!echo {val}

TODO

VIM

vim kernel is a Jupyter kernel for Vim script.

Embedding YouTube videos

YouTube videos can be embedded. The following snippet plays the 10th minute of the video whose id is abcdefghijk:
ytID = 'abcdefghijk'

from IPython.display import YouTubeVideo
YouTubeVideo(ytID, start=600, end=660, width=1280, height=720)

See also

Jupyter Notebook is similar to the notebook interface of other programs such as
Rich Display

Index