Bash Notebooks in Jupyter

So IPython now has a back end called Jupyter that supports a large number of kernels as well as Python.

This means we can write Jupyter notebooks with bash for example.

Here’s how.

Installing Python 3

The bash kernel requires Python 3 and I’ve only installed Anaconda using Python 2.7. How do we easily get Python 3.4 or later as the kernel requires?

Fortunately conda can create a Python environment with Python 3 in one easy step.

conda create -n py3k python=3 ipython notebook

That creates the environment using Python 3 and adds the IPython and Juypter system with notebook support.

This will give us all we need so then source activate py3k will turn it on.

You can tell you are in a conda environment as the bash prompt is prepended with the name of the environment like so py3k)Air:~/dev/Notebooks tonyw$

Getting the kernel

The new bash kernel can be installed with pip and a self installer – pip install bash_kernel ; python -m bash_kernel.install

Now go to the directory containing your notebooks and jupyter notebook will get it running.

Screen Shot 2016-04-09 at 3.37.53 PM

Diagram 1 – A bash notebook

In diagram 1 you can see that we are in a bash notebook as indicated at top right. You can see a bash comman line being run at the bottom.

Screen Shot 2016-04-09 at 3.38.43 PM

Diagram 2 – Creating a new bash notebook

We create a new bash notebook just by selecting New Notebook under the file menu and the sub-item allows you to choose the notebook type as in diagram 2.

The bash notebook works just like a Python one. Enter some code into a cell and press Ctrl-Return to run the code. Have fun.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s