{"record":{"id":"a955b78e70444b21","repo":"django/django","slug":"error-executing-s","errorCode":null,"errorMessage":"Error executing %s","messagePattern":"Error executing (.+?)","errorType":"console","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"django/core/management/utils.py","lineNumber":26,"sourceCode":"from subprocess import run\n\nfrom django.apps import apps as installed_apps\nfrom django.utils.crypto import get_random_string\nfrom django.utils.encoding import DEFAULT_LOCALE_ENCODING\n\nfrom .base import CommandError, CommandParser\n\n\ndef popen_wrapper(args, stdout_encoding=\"utf-8\"):\n    \"\"\"\n    Friendly wrapper around Popen.\n\n    Return stdout output, stderr output, and OS status code.\n    \"\"\"\n    try:\n        p = run(args, capture_output=True, close_fds=os.name != \"nt\")\n    except OSError as err:\n        raise CommandError(\"Error executing %s\" % args[0]) from err\n    return (\n        p.stdout.decode(stdout_encoding),\n        p.stderr.decode(DEFAULT_LOCALE_ENCODING, errors=\"replace\"),\n        p.returncode,\n    )\n\n\ndef handle_extensions(extensions):\n    \"\"\"\n    Organize multiple extensions that are separated with commas or passed by\n    using --extension/-e multiple times.\n\n    For example: running 'django-admin makemessages -e js,txt -e xhtml -a'\n    would result in an extension list: ['.js', '.txt', '.xhtml']\n\n    >>> handle_extensions(['.html', 'html,js,py,py,py,.py', 'py,.py'])\n    {'.html', '.js', '.py'}\n    >>> handle_extensions(['.html, txt,.tpl'])","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/core/management/utils.py#L8-L44","documentation":"A CommandError raised by popen_wrapper when subprocess.run(args) raises OSError before the process can start. This means the executable was not found, not executable, or the spawn itself failed (not a non-zero exit from a successfully launched program).","triggerScenarios":"Calling a management command that shells out to an external tool which is not installed: `makemessages` without gettext (`msgfmt`/`xgettext`), or GIS commands without GDAL/OGR utilities on PATH.","commonSituations":"Missing system packages (gettext, gdal-bin), PATH not including the tool's directory, wrong executable name passed to popen_wrapper, or running in a slimmed-down Docker image without dev tools.","solutions":["Install the missing tool (e.g. `apt-get install gettext` for makemessages).","Verify with `which <tool>` or `shutil.which('<tool>')` from the same environment.","Ensure PATH is exported in the shell or service unit that runs manage.py.","If the tool is optional, gate the calling command behind a which() check."],"exampleFix":"# before\n# makemessages fails: 'Error executing xgettext'\n# after\nsudo apt-get install gettext\npython manage.py makemessages -l fr","handlingStrategy":"validation","validationCode":"import shutil\n\ndef tool_available(tool: str) -> bool:\n    return shutil.which(tool) is not None\n\n# example: gate gettext-dependent commands\nif not tool_available('xgettext'):\n    raise EnvironmentError('gettext is required for makemessages')","typeGuard":null,"tryCatchPattern":"from django.core.management.utils import popen_wrapper\nfrom django.core.management.base import CommandError\ntry:\n    out, err, code = popen_wrapper(['xgettext', '--version'])\nexcept CommandError:\n    raise EnvironmentError('xgettext not installed; apt-get install gettext')","preventionTips":["Install system dev tools (gettext, gdal-bin) in CI and production images.","Wrap popen_wrapper callers with a shutil.which check before invoking.","Document required system packages in the project README and Dockerfile."],"tags":["django","management","subprocess","executable","gettext","path"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}