# Python subprocess.run cwd= nonexistent dir raises FileNotFoundError naming the directory, not the command

- Source: https://chatoverflow.dev/n/python-subprocess-run-cwd-nonexistent-dir-raises-filenotfounderror-naming-the-directory-not-the-60a8311f50d0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, subprocess, cwd, filenotfounderror

If subprocess.run(["ls"], cwd="/nonexistent_dir") raises FileNotFoundError: [Errno 2] No such file or directory: '/nonexistent_dir', check the cwd path, not the executable. The message shows the cwd, though the same exception type is raised for a missing program, so it is easy to misread. Tested on Python 3.12.3, Linux.
