sgl-project/sglang · error · RuntimeError

Python did not report an EXT_SUFFIX for native extensions

Error message

Python did not report an EXT_SUFFIX for native extensions

What it means

sysconfig.get_config_var('EXT_SUFFIX') returned empty, so the loader cannot name the cached native extension file. Indicates a broken/unusual Python build.

Source

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

    serialized = json.dumps(
        value, sort_keys=True, separators=(",", ":"), ensure_ascii=True
    ).encode()
    return hashlib.sha256(serialized).hexdigest()


def _cache_root(cache_dir: Path | None) -> Path:
    if cache_dir is not None:
        return Path(cache_dir).expanduser().resolve()
    sglang_cache = envs.SGLANG_CACHE_DIR.get()
    return Path(sglang_cache).expanduser().resolve() / "rust_extensions"


def _cached_extension_path(
    cache_root: Path, crate: _CrateSpec, fingerprint: str
) -> Path:
    extension_suffix = sysconfig.get_config_var("EXT_SUFFIX")
    if not extension_suffix:
        raise RuntimeError("Python did not report an EXT_SUFFIX for native extensions")
    module_leaf = crate.python_module.rsplit(".", 1)[-1]
    return (
        cache_root
        / "artifacts"
        / crate.package
        / fingerprint
        / (module_leaf + extension_suffix)
    )


@contextmanager
def _filesystem_lock(path: Path) -> Iterator[None]:
    path.parent.mkdir(parents=True, exist_ok=True)
    with path.open("a+b") as lock_file:
        fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX)
        try:
            yield
        finally:

View on GitHub (pinned to 0132848349)

Solutions

  1. Use a standard CPython build
  2. Set/repair the interpreter's sysconfig vars or pass a working sys.executable
  3. Run `python -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"` to confirm the environment is broken
Defensive patterns

Strategy: validation

Validate before calling

import sysconfig
assert sysconfig.get_config_var("EXT_SUFFIX"), "unsupported Python build"

Prevention

When it happens

Trigger: load_rust_extension on a Python interpreter built without extension suffix configuration (some embedded, stripped, or exotic builds).

Common situations: Embedded Python distributions, custom minimal Pythons, or sysconfig data missing; rarely on normal CPython installs.

Related errors


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