Conda命令在命令提示符下工作,但不在bash脚本中工作 [英] Conda command working in command prompt but not in bash script
问题描述
我的anaconda(4.5.4)可以正常工作,只要我通过Linux终端(bash shell)使用它即可.但是,在bash脚本中运行conda命令根本不起作用.
my anaconda (4.5.4) works fine as long as I just use it via a linux terminal (bash shell). However, running conda commands in a bash script does not work at all.
脚本test.sh包含以下几行:
The script test.sh containes these lines:
#!/bin/bash
conda --version
conda activate env
现在,运行bash test.sh
会导致错误
test.sh: line 2: conda: command not found
test.sh: line 3: conda: command not found
Now, running bash test.sh
results in the error
test.sh: line 2: conda: command not found
test.sh: line 3: conda: command not found
如推荐用于anaconda版本> 4.4,我的.bashrc不包含
As recommended for anaconda version > 4.4 my .bashrc does not contain
export PATH="/opt/anaconda/bin:$PATH",
但是
. /opt/anaconda/etc/profile.d/conda.sh
谢谢.
推荐答案
感谢@darthbith的评论,我解决了这个问题.
I solved the problem thanks to @darthbith 's comment.
由于conda
是bash函数并且bash函数不能传播到独立的shell(例如,通过执行bash脚本打开),因此必须添加一行
Since conda
is a bash function and bash functions can not be propagated to independent shells (e.g. opened by executing a bash script), one has to add the line
source /opt/anaconda/etc/profile.d/conda.sh
在调用conda命令之前,先到bash脚本.否则bash不会知道conda.
to the bash script before calling conda commands. Otherwise bash will not know about conda.
这篇关于Conda命令在命令提示符下工作,但不在bash脚本中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!