# Problems when running conda environment from Julia

**URL:** https://discourse.julialang.org/t/problems-when-running-conda-environment-from-julia/108988
**Category:** General Usage
**Tags:** run, pipelines
**Created:** [January 18, 2024, 10:02pm UTC](https://discourse.julialang.org/t/problems-when-running-conda-environment-from-julia/108988 "2024-01-18T22:02:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![CrisCool](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@CrisCool](https://discourse.julialang.org/u/CrisCool)
#### Post date: [January 18, 2024, 10:02pm UTC](https://discourse.julialang.org/t/problems-when-running-conda-environment-from-julia/108988/1 "2024-01-18T22:02:30Z")

</div>

Hei julians

I need help!  
I’m running external commands from julia, using run(pipeline(Cmd)).  
The commands (Cmd) are of the type: `conda run -n conda_env external_tool`.  
I have a julia program where I’m running several such commands serially, each with its own conda environment.  
Ussually everything runs smoothly. However, for one particular Cmd, the conda environment is not activated correctly. It tells me that is is ingoring the R\_HOME environmental value. As a result, the command fails, because the wrong R libs are used.

If I take the Cmd and run it directly in bash, it works.  
If I run I do run(pipeline(Cmd)) in REPL, it works.  
If I place the run(pipeline(Cmd)) in a small julia script and run it, it works.  
Only when I run it in my julia program with all the other Cmds, it does not work.

Any ideas what is happening?  
(PS: I’m running from Julia 1.10)

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [January 18, 2024, 10:30pm UTC](https://discourse.julialang.org/t/problems-when-running-conda-environment-from-julia/108988/2 "2024-01-18T22:30:44Z")

</div>

> [@CrisCool](#):
>
> If I take the Cmd and run it directly in bash, it works.

You can run it through the shell by e.g.

```julia
run(`/bin/bash -c "conda run -n conda_env external_tool"`)

```

(Presumably you are missing some environment variable that is only set when you load up the shell, or launch `julia` from within that shell.)

---

<div class="post-metadata">

### Author: ![CrisCool](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@CrisCool](https://discourse.julialang.org/u/CrisCool)
#### Post date: [February 6, 2024, 9:17pm UTC](https://discourse.julialang.org/t/problems-when-running-conda-environment-from-julia/108988/3 "2024-02-06T21:17:14Z")

</div>

thank you for the suggestions, I’ve tested it, but it does not work

---

<div class="post-metadata">

### Author: ![CrisCool](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@CrisCool](https://discourse.julialang.org/u/CrisCool)
#### Post date: [February 8, 2024, 12:16pm UTC](https://discourse.julialang.org/t/problems-when-running-conda-environment-from-julia/108988/4 "2024-02-08T12:16:40Z")

</div>

Ok, so, after a lot of testing and headaches, I found the problem and the solution. Thanks @stevengj for suggesting that it has to do with the environmental variables within Julia. I have to admit, I wasn’t paying to much attention to them.

To layout what was wrong (for some other poor soul hitting the same walls):

- One of my own libraries uses Rcall, which sets different R related entries in julia ENV dictionary. One of this entries was R\_HOME.
- whenever I was doing “conda run -n myenv\_name some\_command …” it was starting the R version from Julia ENV, which was diferrent from the R version in the conda env “myenv\_name”. As a result, “some\_command” was failling, because it had access to a different R version.
- There are two possible ways to fix that, and they are explained on the RCall page: [Installation · RCall.jl](https://juliainterop.github.io/RCall.jl/stable/installation/)
- I chose this way:

```julia
ENV["R_HOME"] = "....directory of R home...."
Pkg.build("RCall")

```

And now verything works just fine.
