FileNotFoundError in subprocess: Command Not Found

FileNotFoundError: [Errno 2] No such file or directory: 'my-command'

Quick Answer

The command you are running with subprocess does not exist or is not on the PATH. Verify installation, use full path, or check with shutil.which().

Why This Happens

subprocess.run() looks for the executable on the system PATH. If not installed or misspelled, it raises FileNotFoundError.

The Problem

import subprocess
result = subprocess.run(['my-script', '--flag'])

The Fix

import subprocess, shutil
if shutil.which('my-script'):
    result = subprocess.run(['my-script', '--flag'])
else:
    print('my-script is not installed')

Step-by-Step Fix

  1. 1

    Verify command exists

    Use shutil.which('command') to check.

  2. 2

    Use full path

    Specify the complete path to the executable.

  3. 3

    Check shell features

    Use shell=True for pipes/redirects, but avoid with untrusted input.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free