[Python] How to display musical notation using music21 in ipython/python with MuseScore...

Discussão em 'Python' iniciado por Stack, Setembro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I am using music21 with MuseScore in an ipython notebook. It works well, the only problem is that every time I create a Stream and then run my_stream.show(), it takes a forever because it waits to open the MuseScore application. This happens even if MuseScore is already open (it opens a second copy of the app, which then closes itself after the image is printed).

    How can I prevent music21 from re-opening MuseScore each time and get it to use the already opened app instead?

    EDIT: Adding version/OS info

    I'm on a mac (OSX 10.10.4) using MuseScore version 2.1.0

    I've also tried the method outlined here to print out sheet music in an ipython notebook but the same thing happened.

    For the second method at least, the problem seems to be in music21/converter/subConverter.py.

    Under

    class ConverterMusicXML(SubConverter):


    There's this section:

    musescoreRun = '"' + musescorePath + '" ' + fp + " -o " + fpOut + " -T 0 "
    if 'dpi' in keywords:
    musescoreRun += " -r " + str(keywords['dpi'])

    if common.runningUnderIPython():
    musescoreRun += " -r " + str(defaults.ipythonImageDpi)

    storedStrErr = sys.stderr
    fileLikeOpen = six.StringIO()
    sys.stderr = fileLikeOpen
    os.system(musescoreRun)
    fileLikeOpen.close()
    sys.stderr = storedStrErr


    I believe that this line in particular

    os.system(musescoreRun)


    is opening MuseScore independently each time, but I can't figure out what to replace it with that will allow music21 to find the already running instance of MuseScore.

    Continue reading...

Compartilhe esta Página