Customizing the Jupyter notebook¶
These are strictly optional.
1. Creating a startup script¶
It is convenient to have a bunch of default imports and set up inline plotting automatically. Here’s how to do it.
Create an ipython profile¶
In [1]:
! ipython profile create
Edit the next cell to set your defaults, then execute it.¶
In [2]:
%%file ~/.ipython/profile_default/startup/start.ipy
import os
import sys
import glob
import operator as op
import itertools as it
from functools import reduce, partial
import numpy as np
import pandas as pd
from pandas import DataFrame, Series
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context("notebook", font_scale=1.5)
%matplotlib inline
Overwriting /Users/cliburn/.ipython/profile_default/startup/start.ipy
Stop and restart your Jupyter kernel¶
2. Change keybindings to emacs¶
In [3]:
! pip install jupyter-emacskeys
Requirement already satisfied: jupyter-emacskeys in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages
Requirement already satisfied: notebook>=4 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from jupyter-emacskeys)
Requirement already satisfied: ipython>=4 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from jupyter-emacskeys)
Requirement already satisfied: traitlets in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: jupyter-client in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: jupyter-core in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: terminado>=0.3.3; sys_platform != "win32" in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: nbconvert in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: ipykernel in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: tornado>=4 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: ipython-genutils in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: nbformat in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: jinja2 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from notebook>=4->jupyter-emacskeys)
Requirement already satisfied: setuptools>=18.5 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: decorator in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.3 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: pygments in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: simplegeneric>0.8 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: appnope; sys_platform == "darwin" in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: pickleshare in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: pexpect; sys_platform != "win32" in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from ipython>=4->jupyter-emacskeys)
Requirement already satisfied: six in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from traitlets->notebook>=4->jupyter-emacskeys)
Requirement already satisfied: pyzmq>=13 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from jupyter-client->notebook>=4->jupyter-emacskeys)
Requirement already satisfied: entrypoints in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from nbconvert->notebook>=4->jupyter-emacskeys)
Requirement already satisfied: mistune!=0.6 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from nbconvert->notebook>=4->jupyter-emacskeys)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from nbformat->notebook>=4->jupyter-emacskeys)
Requirement already satisfied: MarkupSafe in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from jinja2->notebook>=4->jupyter-emacskeys)
Requirement already satisfied: wcwidth in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from prompt-toolkit<2.0.0,>=1.0.3->ipython>=4->jupyter-emacskeys)
Requirement already satisfied: ptyprocess>=0.5 in /Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages (from pexpect; sys_platform != "win32"->ipython>=4->jupyter-emacskeys)
3. Install slide mode (RISE)¶
In [4]:
%%bash
git clone https://github.com/damianavila/RISE.git
cd RISE
python setup.py install
fatal: destination path 'RISE' already exists and is not an empty directory.
4. Install Calico extensions (see videos for what they do)¶
This will not work in the Docker container as you do not have the appropriate permissions. However, you can do this for your local installation if you wish.
In [5]:
import IPython
Execute the next 2 cells to install spell-check, document and cell tools¶
In [9]:
%%bash
ipython install-nbextension https://bitbucket.org/ipre/calico/downloads/calico-spell-check-1.0.zip
ipython install-nbextension https://bitbucket.org/ipre/calico/downloads/calico-document-tools-1.0.zip
ipython install-nbextension https://bitbucket.org/ipre/calico/downloads/calico-cell-tools-1.0.zip
[TerminalIPythonApp] WARNING | Subcommand `ipython install-nbextension` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter install-nbextension` in the future
Downloading: https://bitbucket.org/ipre/calico/downloads/calico-spell-check-1.0.zip -> /var/folders/xf/rzdg30ps11g93j3w0h589q780000gn/T/tmpdclmwqan/calico-spell-check-1.0.zip
Extracting: /var/folders/xf/rzdg30ps11g93j3w0h589q780000gn/T/tmpdclmwqan/calico-spell-check-1.0.zip -> /usr/local/share/jupyter/nbextensions
[TerminalIPythonApp] WARNING | Subcommand `ipython install-nbextension` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter install-nbextension` in the future
Downloading: https://bitbucket.org/ipre/calico/downloads/calico-document-tools-1.0.zip -> /var/folders/xf/rzdg30ps11g93j3w0h589q780000gn/T/tmp21fjueux/calico-document-tools-1.0.zip
Extracting: /var/folders/xf/rzdg30ps11g93j3w0h589q780000gn/T/tmp21fjueux/calico-document-tools-1.0.zip -> /usr/local/share/jupyter/nbextensions
[TerminalIPythonApp] WARNING | Subcommand `ipython install-nbextension` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter install-nbextension` in the future
Downloading: https://bitbucket.org/ipre/calico/downloads/calico-cell-tools-1.0.zip -> /var/folders/xf/rzdg30ps11g93j3w0h589q780000gn/T/tmpxarme5ac/calico-cell-tools-1.0.zip
Extracting: /var/folders/xf/rzdg30ps11g93j3w0h589q780000gn/T/tmpxarme5ac/calico-cell-tools-1.0.zip -> /usr/local/share/jupyter/nbextensions
In [10]:
%%file ~/.jupyter/custom/custom.js
require(['base/js/utils'],
function(utils) {
utils.load_extensions('calico-spell-check',
'calico-document-tools',
'calico-cell-tools');
});
Writing /Users/cliburn/.jupyter/custom/custom.js
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-10-b8e0197cdb2c> in <module>()
----> 1 get_ipython().run_cell_magic('file', '~/.jupyter/custom/custom.js', "\nrequire(['base/js/utils'],\n function(utils) {\n utils.load_extensions('calico-spell-check',\n 'calico-document-tools',\n 'calico-cell-tools');\n });")
/Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2113 magic_arg_s = self.var_expand(line, stack_depth)
2114 with self.builtin_trap:
-> 2115 result = fn(magic_arg_s, cell)
2116 return result
2117
/Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages/IPython/core/magic.py in __call__(self, *args, **kwargs)
676 self._in_call = True
677 try:
--> 678 return fn(*args, **kwargs)
679 finally:
680 self._in_call = False
<decorator-gen-103> in writefile(self, line, cell)
/Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
186 # but it's overkill for just that one bit of state.
187 def magic_deco(arg):
--> 188 call = lambda f, *a, **k: f(*a, **k)
189
190 if callable(arg):
/Users/cliburn/anaconda2/envs/p3/lib/python3.5/site-packages/IPython/core/magics/osm.py in writefile(self, line, cell)
787
788 mode = 'a' if args.append else 'w'
--> 789 with io.open(filename, mode, encoding='utf-8') as f:
790 f.write(cell)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/cliburn/.jupyter/custom/custom.js'