Search code examples
pythonvenvabjad

abjad.show() issues "FileNotFoundError: [WinError 2] The system cannot find the file specified" in Python


Here's a basic, simple 'abjad' code that one can find in any 'abjad' documentation:

import abjad
n = abjad.Note("c'4")
abjad.show(n)

And here's the full traceback produced by the above code:

Traceback (most recent call last):
  File "R:\W\y.py", line 122, in <module>
    abjad.show(n)
  File "R:\W\venv\Lib\site-packages\abjad\io.py", line 672, in show
    result = illustrator()
             ^^^^^^^^^^^^^
  File "R:\W\venv\Lib\site-packages\abjad\io.py", line 75, in __call__
    string = self.string or self.get_string()
                            ^^^^^^^^^^^^^^^^^
  File "R:\W\venv\Lib\site-packages\abjad\io.py", line 152, in get_string
    return lilypond_file._get_lilypond_format()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "R:\W\venv\Lib\site-packages\abjad\lilypondfile.py", line 474, in _get_lilypond_format
    string = configuration.get_lilypond_version_string()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "R:\W\venv\Lib\site-packages\abjad\configuration.py", line 388, in get_lilypond_version_string
    proc = subprocess.run(command, stdout=subprocess.PIPE)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "G:\Python3.12\Lib\subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "G:\Python3.12\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "G:\Python3.12\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified

Note: I debugged 'subprocess.py' and saw that 'executable' was None, but I couldn't find what it was expected to be.

I have installed abjad in a virtual environment, using both Python 3.10 and Python 3.12. And I have tried with both abjad versions, 3.19 & 3.21. Same story.

I have installed hundreds of Python packages ... I can't remember this case evere having occurred.

Any idea why's this happening?


Solution

  • Looking at the source of "...\abjad\configuration.py", line 388 (as pointed to by the error message), we have the following lines:

    command = ["lilypond", "--version"]
    proc = subprocess.run(command, stdout=subprocess.PIPE)
    

    So the process is trying to run the command "lilypond --version", and failing because Windows cannot find an executable file or command script with that name. You should check where that command is installed and ensure that its full path is added to your PATH environment variable.