{"record":{"id":"ae61433b4c79b2e5","repo":"sgl-project/sglang","slug":"lmcache-is-not-installed-please-install-it-by-run","errorCode":null,"errorMessage":"LMCache is not installed. Please install it by running `pip install lmcache`","messagePattern":"LMCache is not installed\\. Please install it by running `pip install lmcache`","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/mem_cache/storage/lmcache/lmc_radix_cache.py","lineNumber":31,"sourceCode":"    EvictResult,\n    InitLoadBackParams,\n    MatchPrefixParams,\n    MatchResult,\n)\nfrom sglang.srt.mem_cache.radix_cache import RadixCache, RadixKey, TreeNode\nfrom sglang.srt.runtime_context import get_memory, get_spec\nfrom sglang.srt.utils import create_device_stream, device_stream_context\n\ntry:\n    from lmcache.integration.sglang.multi_process_adapter import LMCacheMPConnector\n    from lmcache.integration.sglang.sglang_adapter import (\n        LMCacheLayerwiseConnector,\n        LoadMetadata,\n        StoreMetadata,\n    )\n    from lmcache.integration.sglang.utils import lmcache_get_config\nexcept ImportError as e:\n    raise RuntimeError(\n        \"LMCache is not installed. Please install it by running `pip install lmcache`\"\n    ) from e\n\n\nif TYPE_CHECKING:\n    from sglang.srt.configs.model_config import ModelConfig\n    from sglang.srt.managers.schedule_batch import Req\n    from sglang.srt.mem_cache.cache_init_params import CacheInitParams\n\nlogger = logging.getLogger(__name__)\n\n\n@dataclass\nclass _LMCacheLoadBackMarker:\n    \"\"\"Carries the data ``init_load_back`` needs from the\n    ``match_prefix`` call in MP mode.\n    \"\"\"\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/storage/lmcache/lmc_radix_cache.py#L13-L49","documentation":"Module-level import of lmcache.integration.sglang (connectors, LoadMetadata/StoreMetadata, lmcache_get_config) failed with ImportError, which is re-raised as RuntimeError telling the user to pip install lmcache. Since the import is at module scope, merely importing lmc_radix_cache triggers it.","triggerScenarios":"Importing LMCacheRadixCache (or any module importing lmc_radix_cache) in a Python environment where lmcache is not installed or its sglang integration extras are missing.","commonSituations":"Enabling LMCache without installing the package; lmcache installed for a different Python interpreter than the one running the scheduler (common in venv/conda mixups); broken lmcache install where the top package imports but integration submodule does not.","solutions":["pip install lmcache in the same interpreter that runs SGLang (python -m pip install lmcache)","Verify with: python -c \"from lmcache.integration.sglang.utils import lmcache_get_config\"","If that fails with a deeper ImportError, reinstall lmcache matching your Python/torch versions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"try:\n    from lmcache.integration.sglang.utils import lmcache_get_config  # noqa: F401\n    LMCACHE_OK = True\nexcept ImportError:\n    LMCACHE_OK = False\n\nassert LMCACHE_OK, 'pip install lmcache in this interpreter'","typeGuard":"def lmcache_available() -> bool:\n    try:\n        import lmcache.integration.sglang  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    from sglang.srt.mem_cache.storage.lmcache.lmc_radix_cache import LMCacheRadixCache\nexcept RuntimeError as e:\n    if 'LMCache is not installed' in str(e):\n        raise SystemExit('install lmcache before enabling --enable-lmcache')\n    raise","preventionTips":["Install lmcache into the exact venv/conda env running sglang and verify with python -c import","Gate the --enable-lmcache flag on an availability check in launch tooling"],"tags":["lmcache","importerror","missing-dependency","installation"],"backgroundTag":"missing-optional-dependency","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}