Set-up IPython Notebook Environment

The first step is to set up the IPython notebook so that it can be most useful. This includes creating a profile, installing some extensions and making sure all useful tools are updated. This notebook should only need to be run once.

Create a profile

A profile is the location where Ipython stores all of your settings. To create a profile just run the following:


In [2]:
# Initialize profile
import IPython
import os.path as path

# Create a profile
profile, = !ipython locate profile
if not profile:
    !ipython profile create
print 'Your profile is located at:\t', profile

# Get local paths for later use
ip = IPython.get_ipython()
nbext = path.join(ip.ipython_dir, 'nbextensions')
custom = path.join(profile, 'static/custom/custom.js')

print "Extension files should be placed in: ", nbext
print "Extension settings should be added to: ", custom


Your profile is located at:	/home/jfear/.ipython/profile_default
Extension files should be placed in:  /home/jfear/.ipython/nbextensions
Extension settings should be added to:  /home/jfear/.ipython/profile_default/static/custom/custom.js

Install useful extensions

There are many IPython and IPython notebook extensions available.

Github List of IPython extensions - https://github.com/ipython/ipython/wiki/Extensions-Index

Github List of IPython notebook extensions - https://github.com/ipython-contrib/IPython-notebook-extensions

Lets go ahead and install 4 notebook extensions that I find very useful. To install an extension you first download the extension and place it in:


In [6]:
print nbext


/home/jfear/.ipython/nbextensions

Then need to edit the file:


In [4]:
print custom


/home/jfear/.ipython/profile_default/static/custom/custom.js

and add an IPython load statment:

`IPython.load_extensions('name_of_extension');`

Download Extensions

Spell checker

IPython notebook does not have spell check by default. There are a variety of spell check extensions that have been created. None of these extensions are perfect, but the 'Spell Checking' extension from the Calico project (http://calicoproject.org/ICalico) does all that I need. Here is a youtube video describing the extension:


In [56]:
from IPython.display import YouTubeVideo
YouTubeVideo('o4xCp3b4oCw')


Out[56]:

The following command will download and copy the extension to the appropriate location.


In [2]:
!ipython install-nbextension https://bitbucket.org/ipre/calico/downloads/calico-spell-check-1.0.zip --user


downloading https://bitbucket.org/ipre/calico/downloads/calico-spell-check-1.0.zip to /tmp/tmp720Iny/calico-spell-check-1.0.zip
extracting /tmp/tmp720Iny/calico-spell-check-1.0.zip to /home/jfear/.ipython/nbextensions

Usability tools from the IPython-notebook extensions project

There are three additional extensions from the IPython notebook extension project (https://github.com/ipython-contrib/IPython-notebook-extensions/wiki). I have only looked at some of the 'usability' extensions.

If you are on unix then the following commands will download and place the exentsions in the correct location. If you are on OSX or Windows you need to download:

https://github.com/ipython-contrib/IPython-notebook-extensions/archive/master.zip

Extract it and copy the 'usability' folder into:


In [7]:
print nbext


/home/jfear/.ipython/nbextensions

In [27]:
%%bash -c "mydir=$nbext bash"
cd $HOME/Downloads
wget https://github.com/ipython-contrib/IPython-notebook-extensions/archive/master.zip --quiet
unzip -q master.zip
mv ./IPython-notebook-extensions-master/usability $mydir/

Activate Extensions

Now we need to add the IPython load statments to:


In [8]:
print custom


/home/jfear/.ipython/profile_default/static/custom/custom.js

The following command will install the 4 extensions.


In [9]:
settings="""require(["base/js/events"], function (events) {
    events.on("app_initialized.NotebookApp", function () {
        IPython.load_extensions('calico-spell-check');
        IPython.load_extensions('usability/runtools/main');
        IPython.load_extensions('usability/codefolding/main');
        IPython.load_extensions('usability/python-markdown/main');
    });
});
"""

with open(custom, 'w') as OUT:
        OUT.write(settings)

In [ ]: