Music21 Installation

From Linewaves
Jump to navigation Jump to search

This quick tutorial module explains how to install music21, a library of musicological tools for Python. (Click here if you haven't installed Python yet.)

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. See the appropriate link above for details.

As part of this process, you must install or specify 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:

example_chorale = corpus.parse('bach/bwv65.2.xml')

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 J.S. Bach’s chorale “Ein Kind geborn zu Bethlehem” 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.