Problems when running conda environment from Julia

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)

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

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.)

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

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
  • I chose this way:
ENV["R_HOME"] = " of R home....""RCall")

And now verything works just fine.