{"record":{"id":"5cc9bb26df636991","repo":"sgl-project/sglang","slug":"ray-is-required-for-use-ray-mode-install-it-wit","errorCode":null,"errorMessage":"Ray is required for --use-ray mode. Install it with: pip install 'sglang[ray]'","messagePattern":"Ray is required for --use-ray mode\\. Install it with: pip install 'sglang\\[ray\\]'","errorType":"error_code","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"python/sglang/launch_server.py","lineNumber":49,"sourceCode":"            asyncio.run(serve_grpc_encoder(server_args))\n        else:\n            from sglang.srt.disaggregation.encoder.http_server import launch_server\n\n            launch_server(server_args)\n    elif cfg.smg_grpc_mode:\n        # Legacy SMG gRPC server (--smg-grpc-mode, or the deprecated --grpc-mode\n        # which __post_init__ folds into smg_grpc_mode). The native Rust gRPC\n        # server is a separate path, enabled by --grpc-port, that starts\n        # alongside the default HTTP server below.\n        from sglang.srt.entrypoints.grpc_server import serve_grpc\n\n        asyncio.run(serve_grpc(server_args))\n    elif cfg.use_ray:\n        # Ray mode: HTTP mode with Ray backend.\n        try:\n            from sglang.srt.ray.http_server import launch_server\n        except ImportError:\n            raise ImportError(\n                \"Ray is required for --use-ray mode. \"\n                \"Install it with: pip install 'sglang[ray]'\"\n            )\n\n        launch_server(server_args)\n    else:\n        # Default mode: HTTP mode.\n        from sglang.srt.entrypoints.http_server import launch_server\n\n        launch_server(server_args)\n\n\nif __name__ == \"__main__\":\n    warnings.warn(\n        \"'python -m sglang.launch_server' is still supported, but \"\n        \"'sglang serve' is the recommended entrypoint.\\n\"\n        \"  Example: sglang serve --model-path <model> [options]\",\n        UserWarning,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/launch_server.py#L31-L67","documentation":"launch_server's run_server raises ImportError when --use-ray is set and sglang.srt.ray.http_server cannot be imported, which in practice means the ray extra is not installed. The error message tells you to install the optional ray dependency.","triggerScenarios":"Running python -m sglang.launch_server ... --use-ray without the ray package installed (sglang[ray] extra), so the import of the Ray HTTP server module fails.","commonSituations":"Fresh environments with a bare pip install sglang (no extras), Docker images built without ray, or ray uninstalled/downgraded as a side effect of another package.","solutions":["Install the extra: pip install 'sglang[ray]'","Verify with python -c 'import ray' and re-run the launch command","If ray is installed but import still fails, check for version conflicts or a broken sglang install (pip install --force-reinstall sglang)"],"exampleFix":"# before\npip install sglang\npython -m sglang.launch_server --model ... --use-ray\n\n# after\npip install 'sglang[ray]'\npython -m sglang.launch_server --model ... --use-ray","handlingStrategy":"fallback","validationCode":"try:\n    import ray  # noqa\n    HAS_RAY = True\nexcept ImportError:\n    HAS_RAY = False\nif args.use_ray and not HAS_RAY:\n    raise SystemExit(\"Install first: pip install 'sglang[ray]'\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin sglang[ray] in requirements when using --use-ray","Add a CI step that imports ray for ray-mode configs"],"tags":["sglang","ray","importerror","dependency","server-launch"],"backgroundTag":"missing-optional-dependency","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}