python/cpython · error
cannot open '%s' for reading
Error message
cannot open '%s' for reading
What it means
Build-time error from Programs/_freeze_module.c, the helper that freezes stdlib source into marshalled code objects during CPython builds. read_text() failed to fopen() the input .py path in 'rb' mode — the file does not exist or is unreadable — so the freeze step aborts for that module.
Source
Thrown at Programs/_freeze_module.c:90
PyInitConfig_Free(config);
return;
error:
{
const char *err_msg;
(void)PyInitConfig_GetError(config, &err_msg);
printf("Python init error: %s\n", err_msg);
PyInitConfig_Free(config);
exit(1);
}
}
static const char *
read_text(const char *inpath)
{
FILE *infile = fopen(inpath, "rb");
if (infile == NULL) {
fprintf(stderr, "cannot open '%s' for reading\n", inpath);
return NULL;
}
struct _Py_stat_struct stat;
if (_Py_fstat_noraise(fileno(infile), &stat)) {
fprintf(stderr, "cannot fstat '%s'\n", inpath);
fclose(infile);
return NULL;
}
size_t text_size = (size_t)stat.st_size;
char *text = (char *) malloc(text_size + 1);
if (text == NULL) {
fprintf(stderr, "could not allocate %ld bytes\n", (long) text_size);
fclose(infile);
return NULL;
}
size_t n = fread(text, 1, text_size, infile);View on GitHub (pinned to bc6749cc3b)
Solutions
- Verify the input path exists and is readable: `ls -l <inpath>` and rerun
- Fix the checkout: `git status` / re-clone or `git checkout -- Lib/` to restore missing files
- If adding a new frozen module, ensure the source file path in Makefile/build lists matches the real file
- When invoking manually, use the documented order: _freeze_module <name> <inpath> <outpath>
Defensive patterns
Strategy: validation
Validate before calling
# shell, before building or running the freezer
# [ -r "Lib/os.py" ] || { echo 'missing input'; git checkout -- Lib; exit 1; }
# ./_freeze_module_os.sh # only after inputs exist Prevention
- Build from a complete, clean checkout (git status clean) — avoid sparse clones for CPython
- When adding frozen modules, add the source file in the same commit as the Makefile change
- Wrap manual freezer invocations in a script that test -r's the input first
When it happens
Trigger: Running `_freeze_module name in.py out.c` where in.py does not exist, has wrong permissions, or the path is wrong; in-tree when the build system references a Lib/ file that was deleted, renamed, or not checked out (shallow/sparse clone, interrupted checkout).
Common situations: Building CPython from a dirty or partial checkout; a new frozen module added to the build lists without its source file being committed; out-of-tree builds with wrong relative paths; running _freeze_module manually with misordered arguments.
Related errors
- cannot fstat '%s'
- could not allocate %ld bytes
- read too short: got %ld instead of %ld bytes
- cannot open '%s' for writing
- memory error: could not allocate varname
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/60663698dadb5a24.
Report an issue: GitHub.