3 min read

Jupyter Notebook Extensions

I’m a big fan of literate programming. A week may past or a year and it’s quite easy to forget what we spent all this time working on. Sometimes I find myself trying too hard to refactor and write the most elegant solution. I’d like to think I’m a considerate collaborator and that my comments or write-ups serve as a means of communicating with my teammates. But the truth is, I’m motivated by this imagination of my future self: the hacker that just awoke from an amnesia and has no recollection of typing the squiggly curly braces and wonky %>% operator. In these situations, literate programming can help bring us all back to focus.

Programs must be written for people to read, and only incidentally for machines to execute.
– Harold Abelson, The Wizard Book

SICP

That’s why I’m excited about Anaconda Extensions, which are similar to RStudio Addins.

Here are two features I want to highlight:

I. Changing environments within the notebook

Previously if I forgot to activate the correct environment, I would have to quit the kernel, change directories, and then launch jupyter notebooks again.

$ source activate name-of-my-environment
$ jupyter notebook  

# oh snap, I'm in the wrong directory
# quit the kernel by typing control c 
$ cd into/my/deeply/nested/folder

# repeat the above process again :(
$ source activate name-of-my-environment
$ jupyter notebook

With the extension, I can just change the environment within the Jupyter notebook (without having to terminate the notebook from the commandline). Praise this GUI!
Choose your environment

Here’s the steps to set the extension up. So let’s say I create a new conda environment called notebook_env:

conda create -n notebook_env  

Now I activate the environment notebook_env.

source activate notebook_env

Per the Notebook Conda Kernels Documentation, install the nb_conda_kernels package. This is a package for managing conda environment-based kernels inside of Jupyter.

conda install -n notebook_env nb_conda_kernels

If you want access to other kernels, it’s important to download the specific language for the kernel. For example: I may want to write R code within a Jupyter notebook.

conda install r-irkernel

There are so many kernels to choose from. Gophernotes and SAS, any takers?

II. Make presentations directly from the notebook!

This is awesome, you can directly add images and code to presentation slides. No more screen shots and saved images piling up in presentation folders.

Edit 2019-02-07
At a Python Conference I attended last year, I was introduced to an awesome package called RISE, which I now use for all my presentations & tutorials that I teach from ipython notebooks. I’ll have to add a blurb another time about why I love RISE.

Let’s squelch the Python vs R debates

Just use the tool that works best for the problem at hand. Happy coding!