{"record":{"id":"c9d0021d35b1014e","repo":"facebookresearch/detectron2","slug":"cannot-import-name-relative-import-path-from-or","errorCode":null,"errorMessage":"Cannot import name {relative_import_path} from {original_file}: {cur_file} does not exist.","messagePattern":"Cannot import name (.+?) from (.+?): (.+?) does not exist\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"detectron2/config/lazy.py","lineNumber":140,"sourceCode":"            \"\\n\", \" \"\n        )\n        if not len(relative_import_path):\n            raise ImportError(relative_import_err)\n\n        cur_file = os.path.dirname(original_file)\n        for _ in range(level - 1):\n            cur_file = os.path.dirname(cur_file)\n        cur_name = relative_import_path.lstrip(\".\")\n        for part in cur_name.split(\".\"):\n            cur_file = os.path.join(cur_file, part)\n        if not cur_file.endswith(\".py\"):\n            cur_file += \".py\"\n        if not PathManager.isfile(cur_file):\n            cur_file_no_suffix = cur_file[: -len(\".py\")]\n            if PathManager.isdir(cur_file_no_suffix):\n                raise ImportError(f\"Cannot import from {cur_file_no_suffix}.\" + relative_import_err)\n            else:\n                raise ImportError(\n                    f\"Cannot import name {relative_import_path} from \"\n                    f\"{original_file}: {cur_file} does not exist.\"\n                )\n        return cur_file\n\n    def new_import(name, globals=None, locals=None, fromlist=(), level=0):\n        if (\n            # Only deal with relative imports inside config files\n            level != 0\n            and globals is not None\n            and (globals.get(\"__package__\", \"\") or \"\").startswith(_CFG_PACKAGE_NAME)\n        ):\n            cur_file = find_relative_file(globals[\"__file__\"], name, level)\n            _validate_py_syntax(cur_file)\n            spec = importlib.machinery.ModuleSpec(\n                _random_package_name(cur_file), None, origin=cur_file\n            )\n            module = importlib.util.module_from_spec(spec)","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/detectron2/config/lazy.py#L122-L158","documentation":"The relative import inside a config file resolved to a path that is neither an existing .py file nor a directory — it simply does not exist. Detectron2 reports which name was imported from which config file and the missing path.","triggerScenarios":"In a config file: 'from .common import thing' where common.py does not exist in the same directory (typo, wrong level of '../', file moved).","commonSituations":"Moving/renaming config files without updating importers; wrong number of leading dots ('..base' vs '.base'); case-sensitivity mismatches on case-insensitive filesystems.","solutions":["Check the printed cur_file path and create/rename the config file to match","Fix the number of leading dots for the intended directory level","Fix typos/case in the imported module name"],"exampleFix":"# before (configs/maskrcnn.py)\nfrom .bas_cfg import model  # typo\n# after\nfrom .base_cfg import model","handlingStrategy":"validation","validationCode":"import os, re\nfor m in re.finditer(r\"^\\s*from\\s+(\\.+)([\\w.]*)\\s+import\", open(cfg_path).read(), re.M):\n    d = os.path.dirname(cfg_path)\n    for _ in range(len(m.group(1)) - 1): d = os.path.dirname(d)\n    p = os.path.join(d, *m.group(2).split('.')) + '.py'\n    assert os.path.isfile(p), f\"missing config file: {p}\"","typeGuard":null,"tryCatchPattern":"try:\n    cfg = LazyConfig.load(path)\nexcept ImportError as e:\n    if \"does not exist\" in str(e):\n        print(\"create or fix path for the imported config\")\n    raise","preventionTips":["Keep config imports in sync when moving files","Test that all relative imports resolve in CI","Avoid deep '..' chains in config files"],"tags":["config-file","import-error","file-not-found","lazy-config"],"backgroundTag":"config-relative-import-error","analyzedSha":"a2f4a8771ab77e8411c26b27f24f9489a28a2453","analyzedAt":"2026-08-27T12:08:21.260Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}