检查是否更改了Conda环境。

huangapple go评论43阅读模式
英文:

check if conda environment has changed

问题

我正在更改我的conda环境在一个slurm脚本中,所以我想确保环境已经改成了我想要的。我该如何做到这一点?

我看到了用于“设置”环境变量的代码,但我没有找到用于“获取”环境变量的任何内容。(如果这甚至是我所需要的话)。

英文:

I am changing my conda environment in a slurm script, so I want to make sure the environment has changed to what I intended. How can I do that?

I see codes for "setting" the environment variable, but I didn't find anything for "getting" the environment variable. (if this is even what I need).

答案1

得分: 1

The conda info --envs命令将显示当前可访问的每个conda环境以及其位置。这个命令可以在您的slurm脚本中使用,以查看所需的环境是否存在。

为了验证conda环境是否已激活,您还可以在激活之前和之后使用which python命令。

在您的slurm脚本中,确保在激活环境之前包括eval "$(conda shell.bash hook)"。这是因为在执行slurm作业时未提供您的~/.bashrc,这会阻止它初始化Conda环境的shell。

英文:

The conda info --envs command will show every conda environment that is currently accessible along with its location. This command can be used in your slurm script to see if the desired environment is present.

In order to verify whether the conda environment has been active or not, you can also use the which python command before and after doing so.

In your slurm script, make sure to include eval "$(conda shell.bash hook)" before activating the environment. This is due to the fact that your ~/.bashrc is not supplied when slurm jobs are being done, which prevents it from initialising the shell for Conda environments.

huangapple
  • 本文由 发表于 2023年7月10日 10:58:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76650432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定