Skip to content

Commit

Permalink
[train/tune] Raise actionable error message for missing dependencies (r…
Browse files Browse the repository at this point in the history
…ay-project#38497)

When users `pip install ray` but not `ray[train]`/`ray[tune]`, they can run into confusing error messages, such as:

```
ModuleNotFoundError: No module named 'pyarrow'
```

With this PR, we import the core library requirements in the respective `__init__.py` and raise an actionable error message if they are not found:

```
ImportError: Can't import ray.train as some dependencies are missing. Run `pip install ray[train]` to fix.
```

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
  • Loading branch information
krfricke authored and arvind-chandra committed Aug 31, 2023
1 parent b52b0f9 commit 76fea41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/ray/train/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Try import ray[train] core requirements (defined in setup.py)
try:
import pandas # noqa: F401
import requests # noqa: F401
import pyarrow # noqa: F401
except ImportError as exc:
raise ImportError(
"Can't import ray.train as some dependencies are missing. "
'Run `pip install "ray[train]"` to fix.'
) from exc


from ray._private.usage import usage_lib
from ray.train._internal.data_config import DataConfig
from ray.train._internal.session import get_checkpoint, get_dataset_shard, report
Expand Down
12 changes: 12 additions & 0 deletions python/ray/tune/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Try import ray[tune] core requirements (defined in setup.py)
try:
import pandas # noqa: F401
import requests # noqa: F401
import pyarrow # noqa: F401
except ImportError as exc:
raise ImportError(
"Can't import ray.tune as some dependencies are missing. "
'Run `pip install "ray[tune]"` to fix.'
) from exc


from ray.tune.error import TuneError
from ray.tune.tune import run_experiments, run
from ray.tune.syncer import SyncConfig
Expand Down

0 comments on commit 76fea41

Please sign in to comment.