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")

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”: []

Check to see if it exists:

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

Load it with:

E = notebook.nbextensions.EnableNBExtensionApp()
 Enabling notebook extension usability/sphinx-markdown/main...
       - Validating: problems found:
         - require?  X usability/sphinx-markdown/main

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!