Managing dependencies with runtime_env - Amazon SageMaker AI
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Managing dependencies with runtime_env

Ray runtime_env installs pip packages and ships a working directory to the cluster at run time. You add a dependency without rebuilding a container image, which keeps interactive development fast.

Inject dependencies interactively

Pass runtime_env to ray.init(). Ray installs the packages and uploads the working directory to the cluster before your code runs.

import ray ray.init(runtime_env={ "pip": ["pandas==2.2.2", "scikit-learn"], "working_dir": "./src", })

Inject dependencies for a submitted job

For a job you submit from the command line, pass the same environment with --working-dir and --runtime-env-json.

ray job submit \ --address sagemaker_ray://my-cluster/my-namespace \ --working-dir ./src \ --runtime-env-json '{"pip": ["pandas==2.2.2", "scikit-learn"]}' \ -- python my-script.py

For the full set of runtime_env fields, including conda environments and environment variables, see Ray runtime environments in the Ray documentation.