{"record":{"id":"17b8cfcf52f998bc","repo":"sgl-project/sglang","slug":"environment-variable-sglang-local-ip-nic-requires","errorCode":null,"errorMessage":"Environment variable SGLANG_LOCAL_IP_NIC requires package netifaces, please install it through 'pip install netifaces'","messagePattern":"Environment variable SGLANG_LOCAL_IP_NIC requires package netifaces, please install it through 'pip install netifaces'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/network.py","lineNumber":273,"sourceCode":"\n    if socket_type == zmq.PUSH:\n        set_send_opt()\n    elif socket_type == zmq.PULL:\n        set_recv_opt()\n    elif socket_type in [zmq.DEALER, zmq.REQ, zmq.REP, zmq.PAIR]:\n        set_send_opt()\n        set_recv_opt()\n    else:\n        raise ValueError(f\"Unsupported socket type: {socket_type}\")\n\n\ndef get_local_ip_by_nic(interface: str = None) -> Optional[str]:\n    if not (interface := interface or os.environ.get(\"SGLANG_LOCAL_IP_NIC\", None)):\n        return None\n    try:\n        import netifaces\n    except ImportError as e:\n        raise ImportError(\n            \"Environment variable SGLANG_LOCAL_IP_NIC requires package netifaces, please install it through 'pip install netifaces'\"\n        ) from e\n\n    try:\n        addresses = netifaces.ifaddresses(interface)\n        if netifaces.AF_INET in addresses:\n            for addr_info in addresses[netifaces.AF_INET]:\n                ip = addr_info.get(\"addr\")\n                if ip and ip != \"127.0.0.1\" and ip != \"0.0.0.0\":\n                    return ip\n        if netifaces.AF_INET6 in addresses:\n            for addr_info in addresses[netifaces.AF_INET6]:\n                ip = addr_info.get(\"addr\")\n                if ip and not ip.startswith(\"fe80::\") and ip != \"::1\":\n                    return ip.split(\"%\")[0]\n    except (ValueError, OSError) as e:\n        logger.warning(\n            f\"{e} Can not get local ip from NIC. Please verify whether SGLANG_LOCAL_IP_NIC is set correctly.\"","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/network.py#L255-L291","documentation":"Setting SGLANG_LOCAL_IP_NIC tells get_local_ip_by_nic to find the host IP attached to a specific NIC via the third-party netifaces package. If that package is not installed, the ImportError is re-raised with instructions to pip install netifaces.","triggerScenarios":"Exporting SGLANG_LOCAL_IP_NIC=eth0 (or passing interface=...) on a host where netifaces is not in the environment.","commonSituations":"Multi-homed GPU nodes where users pin the interconnect NIC; minimal/conda environments missing the optional dependency.","solutions":["pip install netifaces in the environment running sglang.","Or unset SGLANG_LOCAL_IP_NIC and rely on get_local_ip_by_remote fallback.","Prefer SGLANG_LOCAL_IP if a plain IP address is known — it avoids the dependency."],"exampleFix":"# before\nexport SGLANG_LOCAL_IP_NIC=eth0  # ImportError: netifaces missing\n\n# after\npip install netifaces\nexport SGLANG_LOCAL_IP_NIC=eth0","handlingStrategy":"validation","validationCode":"import importlib.util\nif os.environ.get(\"SGLANG_LOCAL_IP_NIC\") and importlib.util.find_spec(\"netifaces\") is None:\n    raise SystemExit(\"pip install netifaces or unset SGLANG_LOCAL_IP_NIC\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer SGLANG_LOCAL_IP with a literal IP to avoid the dependency.","Include netifaces in the environment lockfile when NIC selection is used."],"tags":["network","environment","dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}