Search code examples
pythonipythonenthoughtmusic21musicxml

Display of music21, musicXML PNG objects using iPython Notebook/Enthought Canopy


I am experimenting with the music21 library, in preparation for a Machine Learning project that involves genre classification and categorization. I and following some tutorials available here. I am using MuseScore as my MusicXML program, and I am trying to run the whole thing from iPython.

Although I can run the some of the turtorials from the terminal, some elements don't seem to run well from inside iPython. For example:

In [3]: sBach.show()
Out[3]: <music21.ipython21.objects.IPythonPNGObject at 0x10da0aa10>

The line above shows that the PNG object is created, but not displayed. The expected output for 3 above is the following:

enter image description here Experimenting with the following iPython command, I get a placeholder for an image, but not image.

In [6]: %load_ext music21.ipython21.ipExtension
In [7]: sBach.show()

I can't find any problem with my MusicXMLPath. This tutorial refers to the use of musc21 with Anaconda, but all my developments is done with Enthought, so I prefer not to run another virtual environment to use music21 with iPython.

Is there any way to run music21 in an Enthought/iPython notebook?

enter image description here


Solution

  • This should be in the iPython music21 documentation somewhere, my apologies: iPython in music21 requires Lilypond to be installed for images to be generated within the notebook itself. There hasn't been (and won't be until MuseScore 2.0 is released) a way using MusicXML to generate PNG images of scores directly.

    Edit: 2015 July; music21 2.0 w/ MuseScore 2 will generate the PNG images with MuseScore if it is installed and fallback to Lilypond if it is not installed.