{"record":{"id":"21428db69c3a7dc5","repo":"python/cpython","slug":"posix-spawnattr-setbinpref-failed-to-copy-n","errorCode":null,"errorMessage":"posix_spawnattr_setbinpref failed to copy\\n","messagePattern":"posix_spawnattr_setbinpref failed to copy\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"Mac/Tools/pythonw.c","lineNumber":136,"sourceCode":"\n#elif defined(__i386__)\n    cpu_types[0] = CPU_TYPE_X86;\n\n#elif defined(__arm64__)\n    cpu_types[0] = CPU_TYPE_ARM64;\n\n#else\n#       error \"Unknown CPU\"\n\n#endif\n\n    if (posix_spawnattr_setbinpref_np(spawnattr, count,\n                            cpu_types, &ocount) == -1) {\n        err(1, \"posix_spawnattr_setbinpref\");\n        /* NOTREACHTED */\n    }\n    if (count != ocount) {\n        fprintf(stderr, \"posix_spawnattr_setbinpref failed to copy\\n\");\n        exit(1);\n        /* NOTREACHTED */\n    }\n\n\n    /*\n     * Set flag that causes posix_spawn to behave like execv\n     */\n    flags |= POSIX_SPAWN_SETEXEC;\n    if ((errno = posix_spawnattr_setflags(spawnattr, flags)) != 0) {\n        err(1, \"posix_spawnattr_setflags\");\n        /* NOTREACHTED */\n    }\n}\n#endif\n\nint\nmain(int argc, char **argv) {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Mac/Tools/pythonw.c#L118-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reinstall/run under the matching architecture: `arch -arm64 python3 ...` (or `arch -x86_64` if Rosetta is installed: `softwareupdate --install-rosetta`)","Rebuild or reinstall the Python framework/universal2 build with a current toolchain so pythonw matches the host","Use the plain CLI interpreter binary (python3) instead of the pythonw app-bundle stub if GUI behavior is not needed","Verify the binary's architectures with `lipo -info $(which pythonw)` and install the missing slice or Rosetta"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"# shell check before invoking pythonw\n# lipo -info /usr/local/bin/python3.9/bin/python3.9 2>/dev/null || echo 'binary missing slices'\n# softwareupdate --install-rosetta --agree-to-license   # if x86_64 needed","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install Rosetta before running x86_64 builds on Apple Silicon: softwareupdate --install-rosetta","Pin the architecture explicitly with `arch -arm64`/`arch -x86_64` instead of relying on launcher defaults","Keep macOS/Xcode and framework Python builds updated together","Prefer the plain python3 CLI binary over pythonw unless GUI event-loop behavior is required"],"tags":["macos","cpython","posix-spawn","architecture","startup"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}