The error (raylet) ModuleNotFoundError: No module named 'ray' on worker startup means the Ray package is not installed in the Python environment that the worker process is using. This is a common issue when Ray creates a new virtual environment (e.g., .venv) for the runtime environment, but the Ray package itself is not present in that environment (see discussion, see also).
To fix this, ensure that:
- The Ray package is included in your runtime environment dependencies (e.g., in your
pyproject.toml,requirements.txt, orruntime_envpip/uv list). - If using
uv, make surerayis listed as a dependency so it is installed in the worker’s environment. - Avoid situations where Ray creates a new
.venvthat does not inherit the parent environment’s packages.
Example fix (for runtime_env):
runtime_env = {
"pip": ["ray==2.52.0", ...], # add other dependencies as needed
...
}
Or, if using uv, ensure ray is in your pyproject.toml dependencies.
Would you like more detailed troubleshooting steps?
Sources:
- Ray issue: Ray 2.47 regression: All tasks hang when using uv
- Ray Discuss: raylet ModuleNotFoundError: No module named ‘ray’ with installed ray
Hint: Mention @RunLLM in the post for followups.