class ray.runtime_env.RuntimeEnv(*, py_modules: Optional[List[str]] = None, working_dir: Optional[str] = None, pip: Optional[List[str]] = None, conda: Optional[Union[Dict[str, str], str]] = None, container: Optional[Dict[str, str]] = None, env_vars: Optional[Dict[str, str]] = None, config: Optional[Union[Dict, ray.runtime_env.runtime_env.RuntimeEnvConfig]] = None, _validate: bool = True, **kwargs)[source]#

Bases: dict

This class is used to define a runtime environment for a job, task, or actor.

See Runtime environments for detailed documentation.

This class can be used interchangeably with an unstructured dictionary in the relevant API calls.

Can specify a runtime environment whole job, whether running a script directly on the cluster, using Ray Job submission, or using Ray Client:

from ray.runtime_env import RuntimeEnv
# Starting a single-node local Ray cluster
from ray.runtime_env import RuntimeEnv
# Connecting to remote cluster using Ray Client
ray.init("ray://123.456.7.89:10001", runtime_env=RuntimeEnv(...))

Can specify different runtime environments per-actor or per-task using .options() or the @ray.remote decorator:

from ray.runtime_env import RuntimeEnv
# Invoke a remote task that will run in a specified runtime environment.

# Instantiate an actor that will run in a specified runtime environment.
actor = SomeClass.options(runtime_env=RuntimeEnv(...)).remote()

# Specify a runtime environment in the task definition. Future invocations via
# `g.remote()` will use this runtime environment unless overridden by using
# `.options()` as above.
def g():

# Specify a runtime environment in the actor definition. Future instantiations
# via `MyClass.remote()` will use this runtime environment unless overridden by
# using `.options()` as above.
class MyClass:

Here are some examples of RuntimeEnv initialization:

# Example for using conda
    "channels": ["defaults"], "dependencies": ["codecov"]})
RuntimeEnv(conda="pytorch_p36")   # Found on DLAMIs

# Example for using container
    container={"image": "anyscale/ray-ml:nightly-py38-cpu",
    "worker_path": "/root/python/ray/_private/workers/default_worker.py",
    "run_options": ["--cap-drop SYS_ADMIN","--log-level=debug"]})

# Example for set env_vars
RuntimeEnv(env_vars={"OMP_NUM_THREADS": "32", "TF_WARNINGS": "none"})

# Example for set pip
    pip={"packages":["tensorflow", "requests"], "pip_check": False,
    "pip_version": "==22.0.2;python_version=='3.8.11'"})
  • py_modules – List of URIs (either in the GCS or external storage), each of which is a zip file that will be unpacked and inserted into the PYTHONPATH of the workers.

  • working_dir – URI (either in the GCS or external storage) of a zip file that will be unpacked in the directory of each task/actor.

  • pip – Either a list of pip packages, a string containing the path to a pip requirements.txt file, or a python dictionary that has three fields: 1) packages (required, List[str]): a list of pip packages, 2) pip_check (optional, bool): whether enable pip check at the end of pip install, defaults to False. 3) pip_version (optional, str): the version of pip, Ray will spell the package name β€œpip” in front of the pip_version to form the final requirement string, the syntax of a requirement specifier is defined in full in PEP 508.

  • conda – Either the conda YAML config, the name of a local conda env (e.g., β€œpytorch_p36”), or the path to a conda environment.yaml file. The Ray dependency will be automatically injected into the conda env to ensure compatibility with the cluster Ray. The conda name may be mangled automatically to avoid conflicts between runtime envs. This field cannot be specified at the same time as the β€˜pip’ field. To use pip with conda, please specify your pip dependencies within the conda YAML config: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually

  • container – Require a given (Docker) container image, The Ray worker process will run in a container with this image. The worker_path is the default_worker.py path. The run_options list spec is here: https://docs.docker.com/engine/reference/run/

  • env_vars – Environment variables to set.

  • config – config for runtime environment. Either a dict or a RuntimeEnvConfig. Field: (1) setup_timeout_seconds, the timeout of runtime environment creation, timeout is in seconds.

PublicAPI: This API is stable across Ray releases.

get(name, default=None, data_class=None)[source]#

Return the value for key if key is in the dictionary, else default.

plugin_uris() List[str][source]#

Not implemented yet, always return a empty list