Conda command working in command prompt but not in bash script
I solved the problem thanks to @darthbith 's comment.
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
to the bash script before calling conda commands. Otherwise bash will not know about conda.
If @randomwalker's method doesn't work for you, which it won't any time your script is run in a more basic shell such as sh, then you have two options.
Add this to your script:
eval $(conda shell.bash hook)
Call your script with:
bash -i <scriptname>
so that it runs in your interactive environment.
Let's say you try to access user name with "miky" @ "server" address.First when you login to your user ; learn conda path with "which conda" then probably you will get a path such as "/home/miky/anaconda3/bin/conda"then put your conda commands as follow (in my example i use conda to install a mysql plugin forexample.): shh miky@server -t "/home/miky/anaconda3/bin/conda install -y -c anaconda mysql-connector-python" thats all.