I would guess that there is no file named ‘C4’ in the directory where
your code is running. Note that I know nothing about the music21
module, it is possible that it automaticaly adds a file extension to the
string ‘C4’, etc.
Do you know where your python code is being run?
Try with a full path to where the ‘C4’ file is, also.
Maybe change your code to this to see more information:
import os
import music21
from music21 import note, stream
print("CWD =", os.getcwd())
## n1 = note.Note('C4')
n1 = note.Note('C:/path/to/C4')
n1.show()
Obviously adjust C:/path/to/C4
to match where your music file is.
Note, if you use Windows backslash separators () instead of forward
slashes (/) you will find it easier to use “raw strings”:
r'C:\path\to\C4'
That leading r'
marks the string as a “raw string” - the Python
interpreter will not treat backslashes in the string specially, whereas
normal behaviour is that some backslash escapes have meaning in a
normal string. For example:
'a\nb'
is an ‘a’, a newline, a ‘b’. As a raw string:
r'a\nb'
the string contains an ‘a’, a backslash, an ‘n’, a ‘b’.
Because the Windows path separator (backslash) is also the Python
normal-string escape character, it is better to use “raw strings” for
literal Windows paths to avoid accidents.
Cheers,
Cameron Simpson cs@cskk.id.au