sgl-project/sglang · error · ModuleNotFoundError
no Cargo package under {workspace} declares `[package.metada
Error message
no Cargo package under {workspace} declares `[package.metadata.sglang] python-module = "{python_module}"`; declared modules: {sorted(declared_modules)} What it means
No Cargo package in the workspace declares the requested Python module via `[package.metadata.sglang] python-module = "..."`. The message lists the modules that ARE declared to aid diagnosis.
Source
Thrown at python/sglang/srt/rust_extensions/loader.py:192
package_name = package.get("name")
library = document.get("lib", {}).get("name")
if not package_name or not library:
raise ValueError(
f"{manifest} declares python-module {python_module!r} but must "
"also set `package.name` and `lib.name`"
)
matches.append(
_CrateSpec(
package=package_name,
library=library,
python_module=python_module,
workspace=workspace,
features=tuple(sglang_metadata.get("features", ())),
)
)
if not matches:
raise ModuleNotFoundError(
f"no Cargo package under {workspace} declares "
f'`[package.metadata.sglang] python-module = "{python_module}"`; '
f"declared modules: {sorted(declared_modules)}",
name=python_module,
)
if len(matches) > 1:
raise ValueError(
f"multiple Cargo packages under {workspace} declare python module "
f"{python_module!r}: {sorted(crate.package for crate in matches)}"
)
return matches[0]
def _build_context(crate: _CrateSpec) -> _BuildContext:
source_digest = _source_digest(crate.workspace)
toolchain = {
"cargo": _command_version(
"cargo", "--version", "--verbose", cwd=crate.workspaceView on GitHub (pinned to 0132848349)
Solutions
- Check the declared modules list in the message and fix the python_module spelling
- Add a `[package.metadata.sglang] python-module = "..."` entry to the intended crate's Cargo.toml
- Ensure the crate lives under the workspace being scanned
Defensive patterns
Strategy: validation
Validate before calling
import tomllib, pathlib
declared = set()
for p in pathlib.Path(ws).rglob("Cargo.toml"):
d = tomllib.loads(p.read_text())
m = d.get("package",{}).get("metadata",{}).get("sglang",{}).get("python-module")
if m: declared.add(m)
assert python_module in declared Prevention
- Register every new Rust-backed module in [package.metadata.sglang]
- Keep a single source-of-truth list of python-module names
When it happens
Trigger: Calling load_rust_extension with a python_module string that no crate's sglang metadata declares (typo, module not yet registered).
Common situations: Renaming a Python module without updating Cargo metadata; adding a new extension without the metadata block; misspelling the dotted module name.
Related errors
- multiple Cargo packages under {workspace} declare python mod
- Rust workspace for {python_module} was not found at {workspa
- {name} must have dtype torch.int32
- {name} must be on the same device as block sparse tensors
- {name} must live on CUDA
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/2ca42d2671fd21c5.
Report an issue: GitHub.