sgl-project/sglang · error · AttributeError
module {__name__!r} has no attribute {name!r}
Error message
module {__name__!r} has no attribute {name!r} What it means
envs.py uses a module-level __getattr__ for lazy evaluation of SGLANG_* environment variables. Accessing any attribute of sglang.multimodal_gen.envs that is not a key in environment_variables raises AttributeError instead of returning a lazy value.
Source
Thrown at python/sglang/multimodal_gen/envs.py:410
# Special handling for boolean secondary var (TaylorSeer)
def _secondary_taylorseer_getter():
return get_bool_env_var(
"SGLANG_CACHE_DIT_SECONDARY_TAYLORSEER",
default=os.getenv("SGLANG_CACHE_DIT_TAYLORSEER", "false"),
)
environment_variables["SGLANG_CACHE_DIT_SECONDARY_TAYLORSEER"] = (
_secondary_taylorseer_getter
)
# end-env-vars-definition
def __getattr__(name: str):
# lazy evaluation of environment variables
if name in environment_variables:
return environment_variables[name]()
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
def __dir__():
return list(environment_variables.keys())
View on GitHub (pinned to 0132848349)
Solutions
- Check the environment_variables dict in python/sglang/multimodal_gen/envs.py for the exact accessor name
- Read the value from os.environ directly if it's not exposed as a lazy accessor
- Update to/from renamed accessors after version changes (consult the end-env-vars-definition section)
Example fix
# before
value = envs.SGLANG_SOME_REMOVED_VAR # AttributeError
# after
value = os.environ.get("SGLANG_SOME_REMOVED_VAR", default) Defensive patterns
Strategy: type-guard
Validate before calling
from sglang.multimodal_gen import envs
name = "SGLANG_MY_VAR"
if name not in dir(envs): # __dir__ lists environment_variables keys
value = os.environ.get(name) # fallback to raw env
else:
value = getattr(envs, name) Type guard
def env_or_raw(name: str, default=None):
try:
return getattr(envs, name)
except AttributeError:
return os.environ.get(name, default) Try / catch
try:
val = getattr(envs, "SGLANG_MY_VAR")
except AttributeError:
val = os.environ.get("SGLANG_MY_VAR", default) Prevention
- Use dir(envs) to list valid accessors in your sglang version
- Wrap env access with a helper providing defaults
- Re-check accessor names after upgrading sglang
When it happens
Trigger: `from sglang.multimodal_gen import envs` then `envs.SOME_NAME` where SOME_NAME is not defined in the environment_variables dict (e.g. removed, renamed, or never-defined variable, or accessing a real module attribute like envs.os).
Common situations: Upgrading sglang where an env var was renamed/removed; typos in env var names; assuming every SGLANG_* string has a Python accessor; accessing non-env module attributes through this module.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- module {__name__!r} has no attribute {name!r}
- This browser cannot encode H.264 MP4
- H.264 encoder did not return MP4 decoder config
- This browser does not support gzip stream decoding
- delta payload size mismatch: expected ${expectedSize}, got $
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/7f0601be10d51490.
Report an issue: GitHub.