{"record":{"id":"e59e2f428b7e493f","repo":"ultralytics/yolov5","slug":"source-path-source-does-not-exist","errorCode":null,"errorMessage":"Source path '{source}' does not exist","messagePattern":"Source path '(.+?)' does not exist","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"detect.py","lineNumber":159,"sourceCode":"        from detect import run\n\n        # Run inference on an image\n        run(source='data/images/example.jpg', weights='yolov5s.pt', device='0')\n\n        # Run inference on a video with specific confidence threshold\n        run(source='data/videos/example.mp4', weights='yolov5s.pt', conf_thres=0.4, device='0')\n        ```\n    \"\"\"\n    source = str(source)\n    is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)\n    is_url = source.lower().startswith((\"rtsp://\", \"rtmp://\", \"http://\", \"https://\"))\n    webcam = source.isnumeric() or source.endswith(\".streams\") or (is_url and not is_file)\n    screenshot = source.lower().startswith(\"screen\")\n\n    if not (webcam or screenshot or is_url) and not (\n        Path(source).exists() or (has_magic(source) and glob(source, recursive=True))\n    ):\n        raise FileNotFoundError(f\"Source path '{source}' does not exist\")\n\n    save_img = not nosave and not source.endswith(\".txt\")  # save inference images\n\n    if is_url and is_file:\n        source = check_file(source)  # download\n\n    # Directories\n    save_dir = increment_path(Path(project) / name, exist_ok=exist_ok)  # increment run\n    (save_dir / \"labels\" if save_txt else save_dir).mkdir(parents=True, exist_ok=True)  # make dir\n\n    # Load model\n    device = select_device(device)\n    model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)\n    stride, names, pt = model.stride, model.names, model.pt\n    imgsz = check_img_size(imgsz, s=stride)  # check image size\n\n    # Dataloader\n    bs = 1  # batch_size","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/ultralytics/yolov5/blob/20d1d78a08277e365d57bfa3a2cce752772d9e59/detect.py#L141-L177","documentation":"detect.py run() raises FileNotFoundError when the inference source is neither a webcam index/stream URL/screenshot keyword nor an existing path or a resolvable glob pattern. The check uses has_magic to allow wildcards, so any non-magic literal path that does not exist on disk is rejected before the model is loaded. This is the first validation in run(), so it fails fast with no GPU work done.","triggerScenarios":"run(source='data/videos/example.mp4') when that demo file is absent; passing a relative path while the process cwd differs from the repo root; a typo'd image path with no wildcard characters; an NAS/mount path that is not mounted at run time.","commonSituations":"Running detect.py from outside the repo clone where the default example.mp4 does not exist; Docker containers where the data/ directory was not copied in; CI jobs with missing test fixtures; symlinked paths that are broken.","solutions":["Verify the path exists from the same cwd: python -c \"from pathlib import Path; print(Path('your/source').exists())\".","Use an absolute path for the source argument to remove cwd ambiguity.","Use a glob pattern (e.g. source='images/*.jpg') which is expanded by the has_magic branch instead of the exists() check.","Use a supported stream: webcam index ('0'), rtsp://http:// URL, or 'screen' for screenshots."],"exampleFix":"# before\nrun(source='data/videos/example.mp4', weights='yolov5s.pt')  # file missing\n\n# after\nrun(source=str(ROOT / 'data/images'), weights='yolov5s.pt')  # bundled demo images","handlingStrategy":"validation","validationCode":"from pathlib import Path\nfrom detect import has_magic\n\ndef source_ok(source: str) -> bool:\n    s = str(source)\n    is_file = Path(s).suffix[1:] in (IMG_FORMATS + VID_FORMATS)\n    is_url = s.lower().startswith((\"rtsp://\", \"rtmp://\", \"http://\", \"https://\"))\n    webcam = s.isnumeric() or s.endswith(\".streams\") or (is_url and not is_file)\n    screenshot = s.lower().startswith(\"screen\")\n    return bool(webcam or screenshot or is_url or Path(s).exists() or (has_magic(s) and glob.glob(s, recursive=True)))","typeGuard":"def is_usable_source(source: str) -> bool:\n    \"\"\"True if detect.run() will accept this source without FileNotFoundError.\"\"\"\n    from pathlib import Path\n    from utils.general import IMG_FORMATS, VID_FORMATS\n    s = str(source)\n    if s.isnumeric() or s.endswith('.streams') or s.lower().startswith(('rtsp://', 'rtmp://', 'http://', 'https://', 'screen')):\n        return True\n    return Path(s).exists() or '*' in s","tryCatchPattern":null,"preventionTips":["Prefer absolute paths or paths anchored to a known ROOT constant.","Use glob patterns for batches so missing matches do not raise.","Validate sources in job config before submitting to a queue."],"tags":["inference","source-path","filesystem","cli"],"backgroundTag":null,"analyzedSha":"20d1d78a08277e365d57bfa3a2cce752772d9e59","analyzedAt":"2026-08-15T02:56:15.443Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}