From d7b0ac21bebff0a459372f6efdae719425e310c4 Mon Sep 17 00:00:00 2001 From: Archit Kulkarni Date: Mon, 27 Nov 2023 11:24:20 -0600 Subject: [PATCH] [Cluster launcher] Add friendly warning for missing boto3 and googleapiclient imports (#39942) Adds a friendlier warning when required packages for the cluster launcher are missing. boto3 in the case of AWS, and googleapiclient for GCP Related issue number Closes #39941 --------- Signed-off-by: Archit Kulkarni Signed-off-by: Archit Kulkarni --- python/ray/autoscaler/_private/providers.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/python/ray/autoscaler/_private/providers.py b/python/ray/autoscaler/_private/providers.py index 2f45cd2fe17d4..6a99ce486f240 100644 --- a/python/ray/autoscaler/_private/providers.py +++ b/python/ray/autoscaler/_private/providers.py @@ -26,12 +26,30 @@ def _import_aws(provider_config): + try: + # boto3 and botocore are imported in multiple places in the codebase, + # so we just import them here to ensure that they are installed. + import boto3 # noqa: F401 + except ImportError as e: + raise ImportError( + "The Ray AWS VM launcher requires the AWS SDK for Python (Boto3) " + "to be installed. You can install it with `pip install boto3`." + ) from e + from ray.autoscaler._private.aws.node_provider import AWSNodeProvider return AWSNodeProvider def _import_gcp(provider_config): + try: + import googleapiclient # noqa: F401 + except ImportError as e: + raise ImportError( + "The Ray GCP VM launcher requires the Google API Client to be installed. " + "You can install it with `pip install google-api-python-client`." + ) from e + from ray.autoscaler._private.gcp.node_provider import GCPNodeProvider return GCPNodeProvider