jupyter notebook extensions - vicgalle/wiki-example GitHub Wiki

Quick way

  • 1.Installation
    • With conda:
      $ conda install -c conda-forge jupyter_contrib_nbextensions jupyter_nbextensions_configurator
      
    • Or with pip:
      $ pip install jupyter_nbextensions_configurator jupyter_contrib_nbextensions
      
  • 2.Configuration
    $ jupyter contrib nbextension install --user
    $ jupyter nbextensions_configurator enable --user
    

Installing Jupyter Notebook Extensions

To install the jupyter_contrib_nbextensions notebook extensions, three steps are required. First, the Python pip package needs to be installed. Then, the notebook extensions themselves need to be copied to the Jupyter data directory. Finally, the installed notebook extensions can be enabled, either by using built-in Jupyter commands, or more conveniently by using the jupyter_nbextensions_configurator server extension, which is installed as a dependency of this repo.

The Python package installation step is necessary to allow painless installation of the nbextensions together with additional items like nbconvert templates, pre-/postprocessors, and exporters.

1. Install the python package

PIP

All of the nbextensions in this repo are provided as parts of a python package, which is installable in the usual manner, using pip or the setup.py script. To install the current version from PyPi, simply type

$ pip install jupyter_contrib_nbextensions

Alternatively, you can install directly from the current master branch of the repository

$ pip install https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tarball/master

All the usual pip options apply, e.g. using pip's --upgrade flag to force an upgrade, or -e for an editable install.

Conda

There are conda packages for the notebook extensions and the jupyter_nbextensions_configurator available from conda-forge. You can install both using

$ conda install -c conda-forge jupyter_contrib_nbextensions

This also automatically installs the Javascript and CSS files (using jupyter contrib nbextension install --sys-prefix), so the second installation step below can therefore be skipped.

2. Install javascript and css files

This step copies the nbextensions' javascript and css files into the jupyter server's search directory, and edits some jupyter config files. A jupyter subcommand is provided for the purpose:

$ jupyter contrib nbextension install --user

The command does two things: installs nbextension files, and edits nbconvert config files. The first part is essentially a wrapper around the notebook-provided jupyter nbextension install, and copies relevant javascript and css files to the appropriate jupyter data directory. The second part edits the config files jupyter_nbconvert_config.jsonand jupyter_notebook_config.json as noted below in the options. The command can take most of the same options as the jupyter-provided versions, including

  • --user to install into the user's home jupyter directories
  • --system to perform installation into system-wide jupyter directories
  • --sys-prefix to install into python's sys.prefix, useful for instance in virtual environments, such as with conda
  • --symlink to symlink the nbextensions rather than copying each file (recommended, on non-Windows platforms).
  • --debug, for more-verbose output

In addition, two further option flags are provided to perform either only the config-editing operations, or only the file-copy operations:

  • --only-files to install nbextension files without editing any config files
  • --only-config to edit the config files without copying/symlinking any nbextension files. This edits the following files in the applicable jupyter config directory:
    • jupyter_nbconvert_config.json to use some of the classes provided in the python module jupyter_contrib_nbextensions.nbconvert_support
    • jupyter_notebook_config.json to enable the serverextension jupyter_nbextensions_configurator.

Finally, the --perform-running-check option flag is provided in order to prevent the installation from proceeding if a notebook server appears to be currently running (by default, the install will still be performed, even if a notebook server appears to be running).

An analogous uninstall command is also provided, to remove all of the nbextension files from the jupyter directories.

Intalling Jupyter NbExtensions Configurator

For those using conda, you can now get jupyter_nbextensions_configurator from the excellent conda-forge channel in a single command:

$ conda install -c conda-forge jupyter_nbextensions_configurator

For those not using conda, the installation has two steps:

  1. Installing the pip package. This should be as simple as
    $ pip install jupyter_nbextensions_configurator
    
  2. Configuring the notebook server to load the server extension. A jupyter subcommand is provided for this. You can enable the serverextension and the configurator nbextensions listed below for the current user with
    $ jupyter nbextensions_configurator enable --user
    
    The command accepts the same flags as the jupyter serverextension command provided by notebook versions >= 4.2, including --system to enable in system-wide config (the default), or --sys-prefix to enable in config files inside python's sys.prefix, such as for a virtual environment. The provided jupyter nbextensions_configurator command can also be used to disable.

Once installed, you'll need to restart the notebook server. Once restarted, you should be able to find the configurator user interfaces as described below.

Sources: