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

5

6

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

Ravishment answered 12/1, 2014 at 6:29 Comment(0)
T
3

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.

Todtoday answered 21/1, 2014 at 19:9 Comment(1)
to set it up to find MuseScore set us = environment.UserSettings(); us['musescoreDirectPNGPath'] = "/Applications/MuseScore 2.app/Contents/MacOS/mscore" (or wherever you have it)Todtoday
E
4

I have been grappling with this issue myself. ... Have you set your musicxmlPath in music21? If you have not, it's done via environment.set(key, value). You can query for available keys with environment.keys(). I hope this isn't too simple an answer, but it cleared up the problem for me.

Elephus answered 16/7, 2015 at 22:43 Comment(0)
T
3

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.

Todtoday answered 21/1, 2014 at 19:9 Comment(1)
to set it up to find MuseScore set us = environment.UserSettings(); us['musescoreDirectPNGPath'] = "/Applications/MuseScore 2.app/Contents/MacOS/mscore" (or wherever you have it)Todtoday
C
2

If not yet tried, some steps to isolate the cause of the problem:

1) Update to the latest Canopy (Edit: currently 1.4.1) (might help this, will help generally, won't hurt).

2) Change the Pylab backend in Canopy's IPython shell to "Inline (SVG)", via Preferences / Python. (The default Qt backend in that shell conflicts with music21's use of the tkinter library.)

3) Test your script in that shell rather than in the notebook.

4) Ensure that Canopy User Python is your default Python in a Terminal window, as described here.

5) Test your scripts inside of plain ipython terminal (from Terminal, type ipython).

6) Test in ipython terminal in pylab mode (ipython qtconsole --pylab=inline).

7) Test your scripts inside of ipython notebook running in a regular browser (from Terminal, type ipython notebook, and/or ipython notebook --pylab=inline).

Calabro answered 12/1, 2014 at 16:59 Comment(4)
Thank you Jonathan. Points 1 to 5 are fine, meaning that Canopy 1.2 is my current version, changed Pylab backend to SVG, Canopy is my default Python, etc. Nevertheless, for point 6 (ipython --pylab=inline), I get the following: WARNING: 'inline' not available as pylab backend, using 'auto' instead. Still, no PNGs are showing; maybe the --pylab thing is just part of the problem.Ravishment
Sorry, my slop. Inline graphics are not available in a text console, of course. Fixed to ipython qtconsole --pylab=inline. But if by "Points 1-5 are fine" you mean that your script works in all of them, then you actually don't need to test (6), just move on to (7). Could you confirm which variations work for you?Calabro
I still don't get the PNGs in iPython or notebook. Points 1-5 meant that all my setting were correct and that point 5 was giving me the same issues as in the notebook. I need to research this a little more, I think the problem is outside iPython.Ravishment
Just to check.. any chance that that the music21 window is popping up in the background (so not visible, but actually there)?Calabro
T
0

Had similar issues before. It's the same problem when people try to use plot function in ipython/jupyter notebook. You need to call

%matplotlib inline

Tablet answered 3/3, 2017 at 8:6 Comment(0)
B
0

For me the issue was solved by uninstalling the snap version of musescore and installing it from ppa:mscore-ubuntu/mscore3-stable via https://launchpad.net/~mscore-ubuntu/+archive/ubuntu/mscore3-stable

Blanks answered 18/2, 2020 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.