can1357/oh-my-pi · error · RuntimeError

%%bash requires a POSIX bash, but none was found. Install Gi

Error message

%%bash requires a POSIX bash, but none was found. Install Git for Windows or add a non-WSL bash to PATH.

What it means

The %%bash cell magic locates a POSIX bash via shutil.which('bash') and rejects WSL's System32 bash.exe, which would execute the cell in a separate Linux environment the user did not intend. On Windows when no non-WSL bash is on PATH (or only system32/bash.exe is found), it raises RuntimeError instructing the user to install Git for Windows or add a non-WSL bash.

Source

Thrown at packages/coding-agent/src/eval/py/runner.py:765

    # separate Linux environment and does not share the Windows filesystem
    # layout or PATH.
    for env_var, suffix in (
        ("ProgramFiles", r"Git\bin\bash.exe"),
        ("ProgramFiles(x86)", r"Git\bin\bash.exe"),
        ("LOCALAPPDATA", r"Programs\Git\bin\bash.exe"),
    ):
        root = os.environ.get(env_var)
        if root:
            candidate = os.path.join(root, suffix)
            if os.path.isfile(candidate):
                return candidate
    found = shutil.which("bash")
    if found and "system32" not in found.lower():
        return found
    # WSL's System32 bash.exe runs in a separate Linux environment, so
    # silently falling back to it would execute the cell somewhere the user
    # did not intend; fail loudly instead.
    raise RuntimeError(
        "%%bash requires a POSIX bash, but none was found. "
        "Install Git for Windows or add a non-WSL bash to PATH."
    )


@cell_magic("bash")
def _magic_cell_bash(args: str, body: str) -> int:
    return _run_shell_body(body, shell_arg=_resolve_bash())


@cell_magic("capture")
def _magic_cell_capture(args: str, body: str) -> str:
    """Capture stdout/stderr of body; bind to ``args`` (a name) if provided."""
    captured = io.StringIO()
    saved_stdout, saved_stderr = sys.stdout, sys.stderr
    sys.stdout = sys.stderr = captured
    try:
        _exec_source(body, _STATE.user_ns)

View on GitHub (pinned to 9690622007)

Solutions

  1. Install Git for Windows (its usr/bin/bash.exe is POSIX) and ensure it is on PATH
  2. Add a non-WSL bash directory (e.g. C:\Program Files\Git\bin) to PATH ahead of System32
  3. Verify with `where bash` that the resolved bash is not under System32
  4. On non-Windows platforms ensure bash is installed and on PATH

Example fix

// before (PowerShell)
# PATH: C:\Windows\System32 only -> %%bash fails
// after (PowerShell)
$env:PATH = "C:\Program Files\Git\bin;$env:PATH"
Defensive patterns

Strategy: fallback

Validate before calling

import shutil
found = shutil.which("bash")
bash_ok = bool(found) and "system32" not in found.lower()

Try / catch

try:
    %%bash
    echo hello
except RuntimeError as e:
    if "requires a POSIX bash" in str(e):
        # use an alternative shell cell or report install instructions
        print("Install Git for Windows or add non-WSL bash to PATH")

Prevention

When it happens

Trigger: Executing a %%bash cell on Windows with bash absent from PATH, or where the only 'bash' on PATH is C:\Windows\System32\bash.exe (WSL launcher). The system32 check is case-insensitive on the resolved path.

Common situations: Fresh Windows machines without Git for Windows, Git installed but not on PATH, or MSYS2/Cygwin bash installed but PATH not updated. Also CI Windows runners lacking a POSIX shell.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/fdfaf9004fedb25a. Report an issue: GitHub.