sgl-project/sglang · error · FileNotFoundError

Rust workspace for {python_module} was not found at {workspa

Error message

Rust workspace for {python_module} was not found at {workspace}

What it means

The Rust extension loader could not find a Cargo.toml at the resolved workspace path, so it cannot discover the crate for the requested Python module. Thrown by _discover_crate during load_rust_extension.

Source

Thrown at python/sglang/srt/rust_extensions/loader.py:148

        _stage_atomically(artifact, extension_path)
        return _load_extension_from_path(crate.python_module, extension_path)


def _import_bundled_extension(module_name: str) -> ModuleType | None:
    try:
        return importlib.import_module(module_name)
    except ModuleNotFoundError as exc:
        if exc.name == module_name:
            return None
        raise


def _discover_crate(workspace: Path, python_module: str) -> _CrateSpec:
    workspace = Path(workspace).resolve()
    workspace_manifest = workspace / "Cargo.toml"
    lockfile = workspace / "Cargo.lock"
    if not workspace_manifest.is_file():
        raise FileNotFoundError(
            f"Rust workspace for {python_module} was not found at {workspace}"
        )
    if not lockfile.is_file():
        raise FileNotFoundError(
            f"{lockfile} is required for reproducible `cargo build --locked` builds"
        )

    matches: list[_CrateSpec] = []
    declared_modules: list[str] = []
    for manifest in _source_files(workspace):
        if manifest.name != "Cargo.toml":
            continue
        with manifest.open("rb") as file:
            document = tomllib.load(file)
        package = document.get("package")
        if not isinstance(package, dict):
            continue
        sglang_metadata = package.get("metadata", {}).get("sglang", {})

View on GitHub (pinned to 0132848349)

Solutions

  1. Verify the workspace path contains Cargo.toml and fix the path argument
  2. Install a wheel that bundles the prebuilt extension so discovery is skipped
  3. Re-clone/restore the missing Rust sources

Example fix

# before
load_rust_extension("sglang._rust.overlap", workspace=Path("/wrong/path"))
# after
load_rust_extension("sglang._rust.overlap", workspace=repo_root / "rust")
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
ws = Path(workspace).resolve()
if not (ws / "Cargo.toml").is_file():
    raise FileNotFoundError(f"no Rust workspace at {ws}; use a wheel with bundled extension")

Try / catch

try:
    load_rust_extension(module, workspace)
except FileNotFoundError as e:
    fallback_to_bundled_or_fail(e)

Prevention

When it happens

Trigger: Calling load_rust_extension(python_module, workspace=...) where workspace lacks Cargo.toml — wrong path, missing checkout, or wheel install without bundled sources where the discovery path defaults incorrectly.

Common situations: Running from an installed wheel where Rust sources aren't shipped; passing an incorrect workspace path; shallow/partial clone missing rust crates.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/6cbd64ea31fd7dd3. Report an issue: GitHub.