python/cpython · critical

posix_spawnattr_setbinpref failed to copy\n

Error message

posix_spawnattr_setbinpref failed to copy\n

What it means

Fatal startup error from CPython's macOS launcher stub pythonw.c. Before exec'ing the real interpreter binary, it calls posix_spawnattr_setbinpref_np() to pin the preferred CPU architecture (arm64 vs x86_64) for the spawn. If the kernel copies fewer architecture entries than requested (count != ocount), the process prints this message and exits(1) — the interpreter never starts.

Source

Thrown at Mac/Tools/pythonw.c:136

#elif defined(__i386__)
    cpu_types[0] = CPU_TYPE_X86;

#elif defined(__arm64__)
    cpu_types[0] = CPU_TYPE_ARM64;

#else
#       error "Unknown CPU"

#endif

    if (posix_spawnattr_setbinpref_np(spawnattr, count,
                            cpu_types, &ocount) == -1) {
        err(1, "posix_spawnattr_setbinpref");
        /* NOTREACHTED */
    }
    if (count != ocount) {
        fprintf(stderr, "posix_spawnattr_setbinpref failed to copy\n");
        exit(1);
        /* NOTREACHTED */
    }


    /*
     * Set flag that causes posix_spawn to behave like execv
     */
    flags |= POSIX_SPAWN_SETEXEC;
    if ((errno = posix_spawnattr_setflags(spawnattr, flags)) != 0) {
        err(1, "posix_spawnattr_setflags");
        /* NOTREACHTED */
    }
}
#endif

int
main(int argc, char **argv) {

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Reinstall/run under the matching architecture: `arch -arm64 python3 ...` (or `arch -x86_64` if Rosetta is installed: `softwareupdate --install-rosetta`)
  2. Rebuild or reinstall the Python framework/universal2 build with a current toolchain so pythonw matches the host
  3. Use the plain CLI interpreter binary (python3) instead of the pythonw app-bundle stub if GUI behavior is not needed
  4. Verify the binary's architectures with `lipo -info $(which pythonw)` and install the missing slice or Rosetta
Defensive patterns

Strategy: fallback

Validate before calling

# shell check before invoking pythonw
# lipo -info /usr/local/bin/python3.9/bin/python3.9 2>/dev/null || echo 'binary missing slices'
# softwareupdate --install-rosetta --agree-to-license   # if x86_64 needed

Prevention

When it happens

Trigger: Running a pythonw (framework/{}.app bundle) binary on a macOS system where the requested architecture list cannot be honored — e.g. an arm64-only process pinned to x86_64 with no Rosetta installed, or a mismatched universal2 build; the check `count != ocount` on the out-count of accepted CPU types failing.

Common situations: Mixed arm64/x86_64 macOS environments after a macOS or Xcode upgrade breaks Rosetta; running a Homebrew or framework build installed for the wrong architecture; stale pythonw launcher built before a macOS update. Users see the shell command die immediately at startup.

Related errors


AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14). Data as JSON: /api/errors/21428db69c3a7dc5. Report an issue: GitHub.