{"record":{"id":"4c24d75639d411fe","repo":"vllm-project/vllm","slug":"module-package-has-no-attribute-name","errorCode":null,"errorMessage":"module {__package__} has no attribute {name}","messagePattern":"module (.+?) has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"vllm/__init__.py","lineNumber":73,"sourceCode":"        PoolingRequestOutput,\n        RequestOutput,\n        ScoringOutput,\n        ScoringRequestOutput,\n    )\n    from vllm.pooling_params import PoolingParams\n    from vllm.sampling_params import SamplingParams\n    from vllm.v1.executor.ray_utils import initialize_ray_cluster\nelse:\n\n    def __getattr__(name: str) -> typing.Any:\n        from importlib import import_module\n\n        if name in MODULE_ATTRS:\n            module_name, attr_name = MODULE_ATTRS[name].split(\":\")\n            module = import_module(module_name, __package__)\n            return getattr(module, attr_name)\n        else:\n            raise AttributeError(f\"module {__package__} has no attribute {name}\")\n\n\n__all__ = [\n    \"__version__\",\n    \"__version_tuple__\",\n    \"LLM\",\n    \"ModelRegistry\",\n    \"PromptType\",\n    \"TextPrompt\",\n    \"TokensPrompt\",\n    \"SamplingParams\",\n    \"RequestOutput\",\n    \"CompletionOutput\",\n    \"PoolingOutput\",\n    \"PoolingRequestOutput\",\n    \"EmbeddingOutput\",\n    \"EmbeddingRequestOutput\",\n    \"ClassificationOutput\",","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/__init__.py#L55-L91","documentation":"vllm/__init__.py uses lazy module-level __getattr__ (PEP 562): only names in the MODULE_ATTRS map (LLM, SamplingParams, ModelRegistry, EngineArgs, RequestOutput, initialize_ray_cluster, etc., see __all__) are importable from the vllm top level, resolved on demand to their defining submodules. Accessing any other attribute through the package (vllm.foo or from vllm import foo) raises this AttributeError to keep import time low.","triggerScenarios":"`from vllm import configure_logger` or `vllm.MyClass` where MyClass was never exported at top level — e.g. utilities, config objects, or engine internals that live in submodules; also hasattr(vllm, name) probes against the lazy map. Note submodule imports (vllm.utils) are handled by the import system and do not raise this; only missing top-level attribute names do.","commonSituations":"Code written against old vLLM versions that eagerly imported many names into the package namespace; IDE autocomplete suggesting symbols that exist in submodules but not in __all__; libraries doing duck-typed feature detection via getattr(vllm, 'X', None) (which works) vs direct attribute access (which raises).","solutions":["Check vllm.__all__ (or the MODULE_ATTRS map in vllm/__init__.py) for the names that are actually re-exported","Import from the defining submodule instead, e.g. `from vllm.utils import ...` or `from vllm.config import ...` — find it with grep or your IDE's go-to-definition against installed vllm","If the symbol existed under this name in an older vllm, consult the migration/deprecation notes and switch to the current import path","Upgrade/downgrade vllm only if the code targets a version whose top-level exports included the name"],"exampleFix":"# before\nimport vllm\nlogger = vllm.configure_logger(...)  # AttributeError\n# after\nfrom vllm.logging_utils import configure_logger\nlogger = configure_logger(...)","handlingStrategy":"type-guard","validationCode":"import vllm\nname = \"SamplingParams\"\nif name not in getattr(vllm, \"__all__\", ()):\n    raise SystemExit(f\"{name} is not exported from the vllm top level; import it from its submodule\")","typeGuard":"def vllm_exports(name: str) -> bool:\n    import vllm\n    return name in vllm.__all__  # MODULE_ATTRS keys, resolved lazily via __getattr__","tryCatchPattern":"try:\n    cls = getattr(vllm, name)\nexcept AttributeError:\n    # fall back to the defining submodule, e.g. vllm.utils / vllm.config\n    cls = getattr(importlib.import_module(f\"vllm.{submodule}\"), name)","preventionTips":["Import internals from their submodules (vllm.utils, vllm.config, vllm.logging_utils), not the package root","Use getattr(vllm, name, None) or check __all__ for feature detection instead of direct attribute access","Pin the vllm version and write imports against that version's documented public API","Remember top-level exports are lazy (PEP 562): accessing them triggers the real submodule import"],"tags":["vllm","lazy-import","pep562","attributeerror","api-surface"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}