`FileNotFoundError: [Errno 2] No such file or directory: 'kubectl'` from `subprocess.run`, though `kubectl` works in your terminal.
IntermediateTroubleshootingRuntime, file, subprocess & encoding errors
Answer
Likely causes → The executable is not on the PATH of the process (cron, systemd and containers have minimal PATHs), or it is a shell alias/function.
Diagnose →
type kubectl; which kubectl
python -c "import shutil; print(shutil.which('kubectl'))"
Fix → Use the absolute path, set PATH in the unit/cron/Dockerfile, or check with shutil.which() and exit with a clear message.
Prevent → Validate required binaries at startup.
More on Runtime, file, subprocess & encoding errors
`KeyError: 'Tags'` while processing `describe_instances` output.Beginner`TypeError: can't compare offset-naive and offset-aware datetimes` in a snapshot-age check.Beginner`UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte` reading a log file.Intermediate`UnicodeEncodeError: 'ascii' codec can't encode character '✓'` when printing in a container.Intermediate`PermissionError: [Errno 13] Permission denied: '/var/log/app/report.json'`Intermediate`OSError: [Errno 24] Too many open files` in a long-running Python service.Intermediate