Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python -- How to rename Musescore path in package music21?

Tags:

python

music21

I tried to install the Python package music21 and am having a problem running it in Windows. Basically, when I tried to run the simple command they give as an example

converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show()

I got an error

SubConverterException: Cannot find a path to the 'mscore' file at C:\Program Files (x86)\MuseScore 2\MuseScore.exe -- download MuseScore

The reason for this is because Musescore.exe is no longer stored in the folder "MuseScore 2" but now in a subfolder called "bin". So the path needs to be set to be "C:\Program Files (x86)\MuseScore 2\bin\MuseScore.exe" in order to access Musescore.

How do I change this?

Full Error

SubConverterException                     Traceback (most recent call last)
<ipython-input-8-46c66c71749d> in <module>()
----> 1 converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show()

C:\Users\MrNoName\Anaconda3\lib\site-packages\music21\stream\__init__.py in show(self, *args, **kwargs)
    255         if self.isSorted is False and self.autoSort:
    256             self.sort()
--> 257         return super(Stream, self).show(*args, **kwargs)
    258 
    259     #---------------------------------------------------------------------------

C:\Users\MrNoName\Anaconda3\lib\site-packages\music21\base.py in show(self, fmt, app, **keywords)
   2586                                  app=app,
   2587                                  subformats=subformats,
-> 2588                                  **keywords)
   2589 
   2590     #--------------------------------------------------------------------------

C:\Users\MrNoName\Anaconda3\lib\site-packages\music21\converter\subConverters.py in show(self, obj, fmt, app, subformats, **keywords)
    312 
    313             if 'Opus' not in obj.classes:
--> 314                 fp = helperSubConverter.write(obj, helperFormat, subformats=helperSubformats)
    315 
    316                 defaults.title = savedDefaultTitle

C:\Users\MrNoName\Anaconda3\lib\site-packages\music21\converter\subConverters.py in write(self, obj, fmt, fp, subformats, **keywords)
    808 
    809         if subformats is not None and 'png' in subformats:
--> 810             fp = self.runThroughMusescore(fp, **keywords)
    811         return fp
    812 

C:\Users\MrNoName\Anaconda3\lib\site-packages\music21\converter\subConverters.py in runThroughMusescore(self, fp, **keywords)
    756             raise SubConverterException(
    757                         "Cannot find a path to the 'mscore' file at " +
--> 758                         "%s -- download MuseScore" % musescorePath)
    759 
    760         fpOut = fp[0:len(fp) - 3]

SubConverterException: Cannot find a path to the 'mscore' file at C:\Program Files (x86)\MuseScore 2\MuseScore.exe -- download MuseScore
like image 714
Mr.NoName Avatar asked Oct 19 '25 03:10

Mr.NoName


2 Answers

For MuseScore 4

import music21

us = music21.environment.UserSettings()
us['musicxmlPath'] = 'C:\\Program Files\\MuseScore 4\\bin\\MuseScore4.exe'
us['musescoreDirectPNGPath'] = 'C:\\Program Files\\MuseScore 4\\bin\\MuseScore4.exe'
us['musicxmlPath']

For MuseScore 3

from music21 import *

us = environment.UserSettings()
us['musicxmlPath'] = 'C:\\Program Files\\MuseScore 3\\bin\\MuseScore3.exe'
us['musescoreDirectPNGPath'] = 'C:\\Program Files\\MuseScore 3\\bin\\MuseScore3.exe'
us['musicxmlPath']

And if it still does not work, try opening the environment.py with sublime or else in C:\Users\YOU\AppData\Local\Programs\Python\Python39\Lib\site-packages\music21\environment.py then change '%PROGRAMFILES%\MuseScore 3\MuseScore.exe' for '%PROGRAMFILES%\MuseScore 3\bin\MuseScore.exe'

like image 119
Patricio F. Calatayud Avatar answered Oct 20 '25 17:10

Patricio F. Calatayud


Do this right after importing music21:

environment.set('musescoreDirectPNGPath', 'C:\\Program Files (x86)\\MuseScore 2\\bin\\MuseScore.exe')
like image 27
Keith Kim Avatar answered Oct 20 '25 17:10

Keith Kim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!