{"record":{"id":"1b81210154b4e89d","repo":"ultralytics/ultralytics","slug":"insufficient-free-disk-space-fmt-bytes-free","errorCode":null,"errorMessage":"Insufficient free disk space {fmt_bytes(free)} < {fmt_bytes(int(file_bytes * sf))} required, Please free {fmt_bytes(int(file_bytes * sf - free))} additional disk space and try again.","messagePattern":"Insufficient free disk space (.+?) < (.+?) required, Please free (.+?) additional disk space and try again\\.","errorType":"exception","errorClass":"MemoryError","httpStatus":null,"severity":"critical","filePath":"ultralytics/utils/downloads.py","lineNumber":249,"sourceCode":"    \"\"\"\n    total, _used, free = shutil.disk_usage(path or Path.cwd())  # bytes\n    # A filesystem that cannot report usage returns 0 total blocks; free == 0 against a valid total is genuinely\n    # full and must still be caught, since `free` counts blocks available to an unprivileged process.\n    if not total or file_bytes * sf < free:\n        return True  # sufficient space\n\n    def fmt_bytes(b):\n        if b < (1 << 20):  # without a KB tier every value under 51 KB renders \"0.0 MB\", hiding how full the disk is\n            return f\"{b / (1 << 10):.1f} KB\"\n        return f\"{b / (1 << 20):.1f} MB\" if b < (1 << 30) else f\"{b / (1 << 30):.3f} GB\"\n\n    # Insufficient space\n    text = (\n        f\"Insufficient free disk space {fmt_bytes(free)} < {fmt_bytes(int(file_bytes * sf))} required, \"\n        f\"Please free {fmt_bytes(int(file_bytes * sf - free))} additional disk space and try again.\"\n    )\n    if hard:\n        raise MemoryError(text)\n    LOGGER.warning(text)\n    return False\n\n\ndef get_google_drive_file_info(link: str) -> tuple[str, str | None]:\n    \"\"\"Retrieve the direct download link and filename for a shareable Google Drive file link.\n\n    Args:\n        link (str): The shareable link of the Google Drive file.\n\n    Returns:\n        url (str): Direct download URL for the Google Drive file.\n        filename (str | None): Original filename of the Google Drive file. If filename extraction fails, returns None.\n\n    Examples:\n        >>> from ultralytics.utils.downloads import get_google_drive_file_info\n        >>> link = \"https://drive.google.com/file/d/1cqT-cJgANNrhIHCrEufUYhQ4RqiWG_lJ/view?usp=drive_link\"\n        >>> url, filename = get_google_drive_file_info(link)","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/ultralytics/ultralytics/blob/0449ea011cfd6c9a0d50a0bf1043aca5190cd476/ultralytics/utils/downloads.py#L231-L267","documentation":"Raised by check_disk_space() (ultralytics/utils/downloads.py) when free space on the target filesystem is below file_bytes * sf (sf defaults to 1.5, a 50% safety margin) and hard=True. It raises MemoryError — chosen deliberately so download retries do not swallow it (safe_download re-raises MemoryError immediately). The message quantifies free vs required bytes and the shortfall.","triggerScenarios":"Downloading large weights or datasets (e.g. COCO) to a nearly full disk or small tmpfs/容器 volume; exporting to a constrained workspace; setting hard=True when calling check_disk_space yourself.","commonSituations":"Docker containers with small writable layers; CI runners with low free disk; /tmp tmpfs limits; long-lived workstations where datasets accumulated.","solutions":["Free at least the shortfall stated in the message (it includes the 1.5x margin)","Point download_dir / output paths at a larger volume and retry","Prune caches: docker system prune, pip cache purge, remove old runs/datasets","If you control the call, use hard=False to get a warning + False return instead"],"exampleFix":"# before\nsafe_download(url='https://.../coco.zip', file='coco.zip')  # MemoryError on full disk\n\n# after\nfrom ultralytics.utils.downloads import check_disk_space\nif not check_disk_space('https://.../coco.zip', '/data', sf=1.5):\n    raise SystemExit('insufficient disk, freeing space before download')\nsafe_download(url='https://.../coco.zip', file='/data/coco.zip')","handlingStrategy":"validation","validationCode":"from ultralytics.utils.downloads import check_disk_space\n\nif not check_disk_space(url='https://example.com/big.zip', path=Path('/data'), sf=1.5):\n    raise SystemExit('free disk space before downloading (need file size x1.5)')","typeGuard":null,"tryCatchPattern":"try:\n    safe_download(url=url, file=f)\nexcept MemoryError as e:\n    raise SystemExit(f'out of disk: {e} — free space or change download dir') from e","preventionTips":["Pre-check free space (>=1.5x expected payload) before large downloads","Point caches/downloads at large volumes, not container overlay or /tmp tmpfs","Prune old runs and datasets periodically in automation"],"tags":["disk-space","download","environment","memory-error"],"backgroundTag":null,"analyzedSha":"0449ea011cfd6c9a0d50a0bf1043aca5190cd476","analyzedAt":"2026-08-15T02:34:13.413Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}