# Using conda in runtime\_env

**URL:** <https://discuss.ray.io/t/using-conda-in-runtime-env/9011>\
**Category:** Ray Core\
**Created:** [January 18, 2023, 1:39pm UTC](https://discuss.ray.io/t/using-conda-in-runtime-env/9011 "2023-01-18T13:39:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AxelN](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/axeln/32/4018_2.png) [@AxelN](https://discuss.ray.io/u/AxelN)\
**Post date:** [January 18, 2023, 1:39pm UTC](https://discuss.ray.io/t/using-conda-in-runtime-env/9011/1 "2023-01-18T13:39:54Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- High: It blocks me to complete my task.

(I am using ray 2.2.0)  
Hi. I am quite new to ray and am setting up a first ray entrypoint. I have created a docker image with a conda environement installed in it that I want to activate when I submit my jobs through the JobSubmissionClient. When I do this my job gets stuck on PENDING and never starts. I think this is because of mismatching python/ray version between the cluster and my local machine, because the documentation states:  
" `conda` environments must have the same Python version as the Ray cluster. Do not list `ray` in the `conda` dependencies, as it will be automatically installed."  
([Environment Dependencies — Ray 2.2.0](https://docs.ray.io/en/latest/ray-core/handling-dependencies.html))

I am launching the job from the same environment I want to run on the cluster but this do not work. When the documentation here states the “cluster” do they refer to what is installed outside of conda, in the conda base environement or the environment I want to run?

---

<div class="post-metadata">

**Author:** ![architkulkarni](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/architkulkarni/32/10_2.png) [@architkulkarni](https://discuss.ray.io/u/architkulkarni)\
**Post date:** [January 19, 2023, 6:36pm UTC](https://discuss.ray.io/t/using-conda-in-runtime-env/9011/2 "2023-01-19T18:36:47Z")

</div>

Hi @AxelN, that comment only applies if you’re using `runtime_env` with the `"conda"` field. Are you using runtime environments? If so, can you see if there are any details in `dashboard_agent.log` or `runtime_env_setup_*.log` about the runtime env setup? By default these logs are located at `/tmp/ray/session_latest/logs`.

---

<div class="post-metadata">

**Author:** ![architkulkarni](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/architkulkarni/32/10_2.png) [@architkulkarni](https://discuss.ray.io/u/architkulkarni)\
**Post date:** [January 19, 2023, 6:40pm UTC](https://discuss.ray.io/t/using-conda-in-runtime-env/9011/3 "2023-01-19T18:40:47Z")

</div>

If you don’t need to specify different environments at runtime, you don’t need to use `runtime_env`. If the Ray cluster was started (i.e. `ray start` was called) inside the desired conda env, then any jobs submitted will automatically use that conda env. So perhaps you could set up your docker image entrypoint to activate the conda env before calling `ray start`.

---

<div class="post-metadata">

**Author:** ![AxelN](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/axeln/32/4018_2.png) [@AxelN](https://discuss.ray.io/u/AxelN)\
**Post date:** [January 26, 2023, 9:29am UTC](https://discuss.ray.io/t/using-conda-in-runtime-env/9011/4 "2023-01-26T09:29:48Z")

</div>

Thanks. Yes I am using a runtime\_env because I have to use conda (some packages I am using are not available in pip) . But using ray start instead could then be an option so will try that, thanks for the help!

---

<div class="post-metadata">

**Author:** ![tuatini](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@tuatini](https://discuss.ray.io/u/tuatini)\
**Post date:** [September 14, 2023, 8:45am UTC](https://discuss.ray.io/t/using-conda-in-runtime-env/9011/5 "2023-09-14T08:45:03Z")

</div>

Thanks for that! In my situation, I’d like to use the `runtime_env` just to upload my code to the worker but I also want the conda env already in the docker image to be used (not one that I specify in the `runtime_env`). Something like this:

```auto
    job_id = client.submit_job(
        # Entrypoint command to execute
        entrypoint=full_command,
        entrypoint_num_cpus=1,
        entrypoint_num_gpus=num_gpus,
        # Ensures the AI code run is always the latest one synchronized with the backend.
        runtime_env={
            "working_dir": working_dir,
        }
    )

```

Specifying the `working_dir` in my case ensures the latest code is pushed to the worker. Unfortunately when I do that the conda env I defined in my `Dockerfile` and used to launch `CMD ["ray", "start", "--log-style=auto", "--address=ray-head:6023", "--num-gpus=1", "--block"]` is not being used ☹ .

Any idea how I can solve this? Thanks!

---

<div class="post-metadata">

**Author:** ![tuatini](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@tuatini](https://discuss.ray.io/u/tuatini)\
**Post date:** [September 14, 2023, 9:03am UTC](https://discuss.ray.io/t/using-conda-in-runtime-env/9011/6 "2023-09-14T09:03:47Z")

</div>

Found it, I just need to specify the name of the conda env in the `runtime_env` parameter like this:

```auto
    job_id = client.submit_job(
        # Entrypoint command to execute
        entrypoint=full_command,
        entrypoint_num_gpus=num_gpus,
        # Ensures the AI code run is always the latest one synchronized with the backend.
        runtime_env={
            "working_dir": working_dir,
            "conda": "base",

        }
    )

```
