Using music21 with the Jupyter (iPython) Notebook

Setting up the Jupyter environment

To get music21 to work it’s best to have a good pip installation first. Then you should be able to simply install jupyter (and IPython if you don’t have it):

$ sudo pip install jupyter $ sudo pip install ipython

Using the web-based Jupyter Notebook

Start jupyter in a directory you want to save files by typing.

`$ jupyter notebook`

Now in the webbrowser you can type commands such as the ones below:

from music21 import *
c = chord.Chord("C4 E4 G4")
c.isConsonant()
 True

And that is basically it! We use sphinx for interwiki links, which, sadly, won’t show up on the notebook, but should render properly.

But I did make a sphinx-markdown Notebook extension. When it’s ready, I’ll put it up. Make a directory “sphinx-markdown” in a “usability” directory in “nbextensions” (mine is at “~/Library/Jupyter/nbextensions”). And put this file there as “main.js”: [https://gist.github.com/mscuthbert/6411762f98f3536712e0]

Check to see if it exists:

import notebook
notebook.nbextensions.check_nbextension('usability/sphinx-markdown', user=True)
 True

Load it with:

E = notebook.nbextensions.EnableNBExtensionApp()
E.toggle_nbextension('usability/sphinx-markdown/main')
 Enabling notebook extension usability/sphinx-markdown/main...
       - Validating: OK
 False

Save, and reload. Then test it with a markdown cell like:

For more information, see, installing IPython/Jupyter for Music21.

And you should get this output:

For more information, see, installing IPython/Jupyter for Music21. :-)

It works!