Music21 Installation

This quick tutorial post explains how to install music21, a library of musicological tools for Python. For general instructions on how to install a Python library, see this page.

How to install music21 on a Mac.

How to install music21 on a PC (Windows).

Once you install music21, you can load it in Python with a single line of code:

from music21 import *

You must configure music21 the first time you run it. Normally, you just need to type:

Simply hit enter. Make sure you load music21 first. See the appropriate link above for details.

As part of this process, you must specify or install a software program to display notation in the MusicXML format. Free options for viewing MusicXML files include Finale Notepad and MuseScore. MusicXML is an emerging standard for encoding digital sheet music.

You can check whether you have configured your notation viewer properly by entering the following code line by line.

First, load the music21 environment:

from music21 import *

Next, load an example file from the music21 corpus:

ex = corpus.parse('beach/prayer_of_a_tired_child.musicxml')

And use the .show() function to display the notation:

If music21 is configured properly on your system, the notation software you chose should automatically begin running, and the notation for Amy Beach’s choral composition “Prayer of a Tired Child” should appear after a moment.

In some cases, the software may present you with an “import” dialog box. Usually you can leave the default settings in place and simply click OK.

It may take a few seconds for the software and file to load. However, if the notation does not appear, return to the configuration process and specify your software of choice. Or consider downloading and installing Finale Notepad or MuseScore, and then run the configuration assistant again.

For more information on the installation process, visit this page.