python/cpython · error
error when writing to '%s'
Error message
error when writing to '%s'
What it means
Build-time error from Programs/_freeze_module.c: after writing the frozen module's C source, ferror(outfile) reports a stream error — typically ENOSPC (disk full) or an I/O error on the output file. The file is closed and write_frozen() returns -1, failing the freeze step.
Source
Thrown at Programs/_freeze_module.c:210
which in turn should cause the EOL style match the C library's text mode */
FILE *outfile = fopen(outpath, "w");
if (outfile == NULL) {
fprintf(stderr, "cannot open '%s' for writing\n", outpath);
return -1;
}
fprintf(outfile, "%s\n", header);
char *arrayname = get_varname(name, "_Py_M__");
if (arrayname == NULL) {
fprintf(stderr, "memory error: could not allocate varname\n");
fclose(outfile);
return -1;
}
write_code(outfile, marshalled, arrayname);
free(arrayname);
if (ferror(outfile)) {
fprintf(stderr, "error when writing to '%s'\n", outpath);
fclose(outfile);
return -1;
}
fclose(outfile);
return 0;
}
int
main(int argc, char *argv[])
{
const char *name, *inpath, *outpath;
_PyImport_FrozenBootstrap = no_modules;
_PyImport_FrozenStdlib = no_modules;
_PyImport_FrozenTest = no_modules;
PyImport_FrozenModules = NULL;
_PyImport_FrozenAliases = aliases;
View on GitHub (pinned to bc6749cc3b)
Solutions
- Free disk space (`df -h`) and rerun the build
- Build on a filesystem with adequate free space; clean previous build dirs (`git clean -fdx` carefully)
- If on a network mount, remount/reconnect and rerun
Defensive patterns
Strategy: retry
Validate before calling
# shell: require free space before the freeze stage
# [ "$(df -Pk "$OUT" | awk 'NR==2{print $4}')" -gt 1048576 ] || { echo 'need >1GB free'; exit 1; } Prevention
- Check df -h before large builds
- Clean stale build directories between full builds
- Avoid network mounts for build outputs when local disk is available
When it happens
Trigger: The output filesystem fills up while write_code() emits the (large) marshalled-data array; I/O errors on the target device; network filesystems dropping mid-write.
Common situations: CI runners or VMs with small /tmp or workspace disks filling during a CPython build; building on NFS/SMB mounts that fail transiently.
Related errors
- cannot open '%s' for reading
- cannot fstat '%s'
- could not allocate %ld bytes
- read too short: got %ld instead of %ld bytes
- cannot open '%s' for writing
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/c6100ffa3878492f.
Report an issue: GitHub.