{"record":{"id":"c70cb8c7b276fb01","repo":"PaddlePaddle/PaddleOCR","slug":"failed-to-mkdir","errorCode":null,"errorMessage":"Failed to mkdir {}","messagePattern":"Failed to mkdir (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"ppocr/utils/save_load.py","lineNumber":63,"sourceCode":"\n\nFLAGS_json_format_model = get_FLAGS_json_format_model()\n\n\ndef _mkdir_if_not_exist(path, logger):\n    \"\"\"\n    mkdir if not exists, ignore the exception when multiprocess mkdir together\n    \"\"\"\n    if not os.path.exists(path):\n        try:\n            os.makedirs(path)\n        except OSError as e:\n            if e.errno == errno.EEXIST and os.path.isdir(path):\n                logger.warning(\n                    \"be happy if some process has already created {}\".format(path)\n                )\n            else:\n                raise OSError(\"Failed to mkdir {}\".format(path))\n\n\ndef load_model(config, model, optimizer=None, model_type=\"det\", ema=None):\n    \"\"\"\n    load model from checkpoint or pretrained_model\n    \"\"\"\n    logger = get_logger()\n    global_config = config[\"Global\"]\n    checkpoints = global_config.get(\"checkpoints\")\n    pretrained_model = global_config.get(\"pretrained_model\")\n    best_model_dict = {}\n    is_float16 = False\n    is_nlp_model = model_type == \"kie\" and config[\"Architecture\"][\"algorithm\"] not in [\n        \"SDMGR\"\n    ]\n\n    if is_nlp_model is True:\n        # NOTE: for kie model dsitillation, resume training is not supported now","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/utils/save_load.py#L45-L81","documentation":"OSError from ppocr/utils/save_load.py mkdir_if_not_exists: os.makedirs(path) failed with an OSError that is NOT the benign EEXIST-race (another process just created the same directory). Typical causes are permission denied on a parent directory, a path component that is actually a file, a read-only filesystem, or an invalid path string.","triggerScenarios":"Training/inference saving checkpoints, inference results, or visualization outputs to a directory that cannot be created: no write permission under the output root, a file occupying a path component (e.g. ./output exists as a file), or NFS/container read-only mounts.","commonSituations":"Running in Docker as non-root against a host-mounted volume; output_dir in config pointing into a protected path like /opt or /; leftover files named like the intended directory; multiprocess training where the race branch is handled but real permission errors are not.","solutions":["Check permissions along the whole path and fix ownership (chown/chmod) or choose a writable output_dir in the config.","Remove or rename any regular file that collides with a directory component of the path.","On containerized runs, ensure the volume is mounted rw and the process user can write it.","Re-run after fixing — the message names the exact failing path."],"exampleFix":"# before\nGlobal:\n  save_model_dir: /opt/models/output  # not writable\n\n# after\nGlobal:\n  save_model_dir: ./output","handlingStrategy":"validation","validationCode":"import os\n\ndef ensure_writable_dir(path) -> None:\n    parent = os.path.dirname(os.path.abspath(path)) or '.'\n    assert os.path.isdir(parent), f'{parent} is not a directory'\n    assert os.access(parent, os.W_OK), f'no write permission under {parent}'\n    os.makedirs(path, exist_ok=True)\n\nensure_writable_dir(cfg['Global']['save_model_dir'])","typeGuard":null,"tryCatchPattern":"try:\n    os.makedirs(path, exist_ok=True)\nexcept OSError as e:\n    if e.errno == errno.EACCES:\n        # pick a writable fallback root instead of failing the whole run\n        path = os.path.join(tempfile.gettempdir(), os.path.basename(path))\n        os.makedirs(path, exist_ok=True)\n    else:\n        raise","preventionTips":["Use writable, preferably relative output roots (./output) in configs.","In containers, verify the process user can write mounted volumes before long runs.","Never name a regular file the same as an intended output directory."],"tags":["filesystem","permissions","save","training"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}