Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyter notebook - items don't show() #260

Closed
psychemedia opened this issue Nov 4, 2017 · 12 comments · Fixed by #1007
Closed

Jupyter notebook - items don't show() #260

psychemedia opened this issue Nov 4, 2017 · 12 comments · Fixed by #1007
Assignees

Comments

@psychemedia
Copy link

Trying to use %load_ext music21.ipython21 in a Jupyter notebook with a .show() method, I get the following error:

SubConverterFileIOException               Traceback (most recent call last)
<ipython-input-10-86df1d1172c0> in <module>()
----> 1 c.show()

/srv/venv/lib/python3.5/site-packages/music21/base.py in show(self, fmt, app, **keywords)
   2627                                  app=app,
   2628                                  subformats=subformats,
-> 2629                                  **keywords)
   2630 
   2631     #--------------------------------------------------------------------------

/srv/venv/lib/python3.5/site-packages/music21/converter/subConverters.py in show(self, obj, fmt, app, subformats, **keywords)
    351             for s in scores:
    352                 fp = helperSubConverter.write(s, helperFormat,
--> 353                                               subformats=helperSubformats, **keywords)
    354 
    355                 if helperSubformats[0] == 'png':

/srv/venv/lib/python3.5/site-packages/music21/converter/subConverters.py in write(self, obj, fmt, fp, subformats, **keywords)
    873                 and ('png' in subformats or 'pdf' in subformats)
    874                 and environLocal['musescoreDirectPNGPath'] != '/skip'):
--> 875             fp = self.runThroughMusescore(fp, subformats, **keywords)
    876 
    877         return fp

/srv/venv/lib/python3.5/site-packages/music21/converter/subConverters.py in runThroughMusescore(self, fp, subformats, **keywords)
    830 
    831         if subformatExtension == 'png':
--> 832             return self.findPNGfpFromXMLfp(fpOut)
    833         else:
    834             return fpOut

/srv/venv/lib/python3.5/site-packages/music21/converter/subConverters.py in findPNGfpFromXMLfp(self, xmlFilePath)
    748             pngfp = xmlFilePath[0:len(xmlFilePath) - 4] + "-001.png"
    749         else:
--> 750             raise SubConverterFileIOException("png file of xml not found. Is your file >999 pages?")
    751         return pngfp
    752 

SubConverterFileIOException: png file of xml not found. Is your file >999 pages?

The following workaround does let me display an image but it's clunky...

from IPython.display import Image
c.show('lily.png')
Image(filename=c.write('lily.png'))

Example set-up from https://github.com/psychemedia/showntell/tree/music running under BinderHub: https://beta.mybinder.org/v2/gh/psychemedia/showntell/music

@mscuthbert
Copy link
Member

Do you have MuseScore installed?

@psychemedia
Copy link
Author

Yes - the following config item - https://github.com/psychemedia/showntell/blob/music/apt.txt - installs:

lilypond
musescore

Py packages that are installed listed here: https://github.com/psychemedia/showntell/blob/music/requirements.txt

@mscuthbert
Copy link
Member

Sorry, but I can't diagnose another app, only a music21 problem. Does .write() create the file normally?

@psychemedia
Copy link
Author

psychemedia commented Nov 5, 2017

If I run:

c = chord.Chord("C4 E4 G4")
c.show('lily.png')
c.write('lily.png')

a file gets written to /tmp.

If I run:

from IPython.display import Image
c = chord.Chord("C4 E4 G4")
c.show('lily.png')
Image(filename=c.write('lily.png'))

the image is displayed.

If I run:

c = chord.Chord("C4 E4 G4")
c.show()

I get the SubConverterFileIOException: png file of xml not found. Is your file >999 pages? error. In fact, I get that error whenever I try to .show() an image, eg from:

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

Could this be an issue with path settings?

I currently have to set the following in the notebook to get the Image() route to work:

environment.UserSettings()['lilypondPath']='/usr/bin/lilypond'
environment.set('pdfPath', '/usr/bin/musescore')
environment.set('graphicsPath', '/usr/bin/musescore')
environment.set("musescoreDirectPNGPath", "/usr/bin/musescore")
environment.set("musicxmlPath", "/usr/bin/musescore")

Could it be that the environment setting is not being picked up by the .show() methods?

A worked example is available on binderhub - https://beta.mybinder.org/v2/gh/psychemedia/showntell/music - in the notebook index_music.ipynb.

@mscuthbert
Copy link
Member

Ah, this is a linux setup -- we do not directly support Linux or other OSes except Mac and Windows. Please see the installation instructions which are quite clear on this point. Sorry, but there's not time on the development staff.

@psychemedia
Copy link
Author

psychemedia commented Nov 5, 2017

On that point, is there a reference Dockerfile anywhere that acts as a reference build and that can be used to demo an interactive music21 setup without the need to install any software (other than some way of running a Docker container)?

My use case is that I want to demo, and maybe use ,music21 but the people I need to convince won't install anything - I need to give them access to a demo notebook environment containing music21 demos via their browser.

I can imagine two possible reference container builds that would help with this:

  • a music21 build on top of one of an official Jupyter notebook image; this would have the advantage of showing how to get music21 up and running properly on a Linux build using a standard/reference Jupyter install; downside is you have no control over the Jupyter Linux environment;
  • an official music21 image that just includes music21, with working examples from Python command line, and then another Jupyter container importing from the music21 container that adds a Jupyter notebook environment.

I had a quick look on Dockerhub, but one image I found on there seems to be broken.

@mscuthbert
Copy link
Member

There isn't a core docker for music21 and it's not something the development team is likely to have time to build or maintain in the near future but definitely it'd be helpful for some. Because my time is limited (many projects plus teaching full time and service) I need to restrict my installation support time to pure vanilla installs of windows and Mac and let power users deal with other configurations on their own.

@psychemedia
Copy link
Author

I'm similarly stretched ito time, and hampered by zero Linux admin skills, but will take a look as and when I get a chance and see if I can find, or pull together, a Dockerfile that means the notebook workaround can be avoided.

@lancioni
Copy link

lancioni commented Feb 2, 2019

The same problem happens with me under Windows 10. It looks definitely like a path issue: first, it gave an error because MuseScore path had a space within, when I reinstalled it with a spaceless path the SubConverterFileIOException error appeared. Everything is working fine under python outside jupyter.

Update: the problems seems rather to lie in the default format for show: if I write c.show() I get the error, while c.show('musicxml') is fine. However, 'musicxml' is the setting for 'showFormat' and 'writeFormat' (and it works fine in python), so the problems seems to be in jupyter not getting the right value.

@songyang-dev
Copy link

Hello @lancioni I tried your method, but my notebook on Google Colab doesn't show anything. It successfully removed the exception, however.

@BrandNewJimZhang
Copy link

Hello @lancioni I tried your method, but my notebook on Google Colab doesn't show anything. It successfully removed the exception, however.

Same problem. :(

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented May 7, 2021

A few things:

  • make sure you are using latest:
!pip install music21==6.7.1
  • make sure you set the musescoreDirectPNGPath
  us = music21.environment.UserSettings()
  us['musescoreDirectPNGPath'] = '/usr/bin/mscore3'
  • You also need to set MuseScore offscreen variables:
import os
os.putenv("QT_QPA_PLATFORM", "offscreen")
from music21 import environment
os.putenv("XDG_RUNTIME_DIR", environment.Environment().getRootTempDir())

See working colab:
https://colab.research.google.com/drive/1XV6iL6UsuDcx-z5J_dI0wELTearcgIgw#scrollTo=lVoOaVXMUxgq

Reopening so we can get points 2 and 3 as defaults for v7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants