Fixes · Checked on 2026-10-03
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
claudeandcodex, are.cmdscripts on Windows. Your terminal finds them throughPATHEXT;subprocesswithout a shell only looks fornpm.exe. -
A relative path.
target/release/app.exeor.venv/Scripts/python.exeonly 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.