Try the demo

FileNotFoundError: [WinError 2] The system cannot find the file specified

The program runs in your terminal, but not from subprocess.run.

The error

>>> subprocess.run(["npm", "--version"])
FileNotFoundError: [WinError 2] The system cannot find the file specified

Why it happens

  • The program isn't an .exe. npm, and the tools npm installs, such as claude and codex, are .cmd scripts on Windows. Your terminal finds them through PATHEXT; subprocess without a shell only looks for npm.exe.
  • A relative path. target/release/app.exe or .venv/Scripts/python.exe only works from the folder it's relative to, and a script or agent often runs from another.

The fix

Resolve the program to a full path first. shutil.which knows about PATHEXT:

import shutil, subprocess

npm = shutil.which("npm")    # C:\Program Files\nodejs\npm.CMD
subprocess.run([npm, "--version"], check=True)

For programs you built, pass an absolute path:

from pathlib import Path
app = Path("target/release/app.exe").resolve()

How DMN learned it

It came up, and was fixed, in 3 of our own sessions. DMN kept the fix as one line: When Python's subprocess.run on Windows raises FileNotFoundError [WinError 2], pass the executable (e.g. dmn.exe, venv python.exe) as an absolute path, not a relative one.

DMN reads your agents' past sessions on your machine. When the same error is fixed the same way in two or more of them, it keeps the fix as a one-line lesson. When the error turns up again, Claude Code is told the fix straight away, and any agent can search what earlier sessions found. How DMN keeps what agents learn.

Stop fixing the same error twice