<p>我希望运行一个简单的shell脚本来简化一些conda环境的管理。通过<code>conda activate</code>在<code>linux</code>操作系统中激活conda环境在shell中工作良好,但在shell脚本中有问题。有人能告诉我为什么会这样吗?</p>
<p>重复此问题的示例:</p>
<pre><code># default conda env
$ conda info|egrep "conda version|active environment"
active environment : base
conda version : 4.6.9
# activate new env to prove that it works
$ conda activate scratch
$ conda info|egrep "conda version|active environment"
active environment : scratch
conda version : 4.6.9
# revert back to my original conda env
$ conda activate base
$ cat shell_script.sh
#!/bin/bash
conda activate scratch
# run shell script - this will produce an error even though it succeeded above
$ ./shell_script.sh
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
</code></pre>