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
- 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
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
- 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
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
- Don't know machine value for archs=%r
- %s
- Argument expected for the %ls options\n
- --check-hash-based-pycs must be one of 'default', 'always',
- Error setting LC_CTYPE, skipping C locale coercion\n
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/21428db69c3a7dc5.
Report an issue: GitHub.