{"record":{"id":"60663698dadb5a24","repo":"python/cpython","slug":"cannot-open-s-for-reading","errorCode":null,"errorMessage":"cannot open '%s' for reading\n","messagePattern":"cannot open '(.+?)' for reading\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Programs/_freeze_module.c","lineNumber":90,"sourceCode":"    PyInitConfig_Free(config);\n    return;\n\nerror:\n    {\n        const char *err_msg;\n        (void)PyInitConfig_GetError(config, &err_msg);\n        printf(\"Python init error: %s\\n\", err_msg);\n        PyInitConfig_Free(config);\n        exit(1);\n    }\n}\n\nstatic const char *\nread_text(const char *inpath)\n{\n    FILE *infile = fopen(inpath, \"rb\");\n    if (infile == NULL) {\n        fprintf(stderr, \"cannot open '%s' for reading\\n\", inpath);\n        return NULL;\n    }\n\n    struct _Py_stat_struct stat;\n    if (_Py_fstat_noraise(fileno(infile), &stat)) {\n        fprintf(stderr, \"cannot fstat '%s'\\n\", inpath);\n        fclose(infile);\n        return NULL;\n    }\n    size_t text_size = (size_t)stat.st_size;\n\n    char *text = (char *) malloc(text_size + 1);\n    if (text == NULL) {\n        fprintf(stderr, \"could not allocate %ld bytes\\n\", (long) text_size);\n        fclose(infile);\n        return NULL;\n    }\n    size_t n = fread(text, 1, text_size, infile);","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Programs/_freeze_module.c#L72-L108","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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>"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# shell, before building or running the freezer\n# [ -r \"Lib/os.py\" ] || { echo 'missing input'; git checkout -- Lib; exit 1; }\n# ./_freeze_module_os.sh  # only after inputs exist","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cpython","build","freeze-module","file-not-found"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}