django/django · error · CommandError

Error executing %s

Error message

Error executing %s

What it means

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).

Source

Thrown at django/core/management/utils.py:26

from subprocess import run

from django.apps import apps as installed_apps
from django.utils.crypto import get_random_string
from django.utils.encoding import DEFAULT_LOCALE_ENCODING

from .base import CommandError, CommandParser


def popen_wrapper(args, stdout_encoding="utf-8"):
    """
    Friendly wrapper around Popen.

    Return stdout output, stderr output, and OS status code.
    """
    try:
        p = run(args, capture_output=True, close_fds=os.name != "nt")
    except OSError as err:
        raise CommandError("Error executing %s" % args[0]) from err
    return (
        p.stdout.decode(stdout_encoding),
        p.stderr.decode(DEFAULT_LOCALE_ENCODING, errors="replace"),
        p.returncode,
    )


def handle_extensions(extensions):
    """
    Organize multiple extensions that are separated with commas or passed by
    using --extension/-e multiple times.

    For example: running 'django-admin makemessages -e js,txt -e xhtml -a'
    would result in an extension list: ['.js', '.txt', '.xhtml']

    >>> handle_extensions(['.html', 'html,js,py,py,py,.py', 'py,.py'])
    {'.html', '.js', '.py'}
    >>> handle_extensions(['.html, txt,.tpl'])

View on GitHub (pinned to ae25a40be0)

Solutions

  1. Install the missing tool (e.g. `apt-get install gettext` for makemessages).
  2. Verify with `which <tool>` or `shutil.which('<tool>')` from the same environment.
  3. Ensure PATH is exported in the shell or service unit that runs manage.py.
  4. If the tool is optional, gate the calling command behind a which() check.

Example fix

# before
# makemessages fails: 'Error executing xgettext'
# after
sudo apt-get install gettext
python manage.py makemessages -l fr
Defensive patterns

Strategy: validation

Validate before calling

import shutil

def tool_available(tool: str) -> bool:
    return shutil.which(tool) is not None

# example: gate gettext-dependent commands
if not tool_available('xgettext'):
    raise EnvironmentError('gettext is required for makemessages')

Try / catch

from django.core.management.utils import popen_wrapper
from django.core.management.base import CommandError
try:
    out, err, code = popen_wrapper(['xgettext', '--version'])
except CommandError:
    raise EnvironmentError('xgettext not installed; apt-get install gettext')

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of django/django@ae25a40be0 (2026-08-06). Data as JSON: /api/errors/a955b78e70444b21. Report an issue: GitHub.