(raylet) ModuleNotFoundError: No module named 'ray' with installed ray


I am using Python==3.10, ray==2.6.1. I am confused why I keep getting this error when I have ray installed:

(raylet)   File "/home/anaconda3/envs/myvirenv_py310/lib/python3.10/site-packages/ray/_private/workers/default_worker.py", line 7, in <module>
(raylet)     import ray
(raylet) ModuleNotFoundError: No module named 'ray'

But there was no such error when I open a python env and import it:

(myvirenv_py310) [ubuntu@myserveraddress00]$ python
Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ray

What I did for trouble shoot:

  • I created a virtual environment with conda python3.10 and installed ray==2.6.1 in the virtual environment using pip install ray==2.6.1.
  • I did make sure that ray was installed in python 3.10 packages directory, it seems that when executing source code default_worker.py in /home/anaconda3/envs/myvirenv_py310/lib/python3.10/site-packages/ray/_private/workers the script somehow cannot locate ray.

I am very confused and stuck on how to debug further, any tips will be very helpful. Thanks!

Just update about how we solved this issue:

The issue happened because the script running ray in virtual env was trying to find intalled libraries from python base directs but not from libraries installed in virtual env, to solve this issue simply change codes in ray.init():

ray.init({'conda':'<virtual env name>'})