Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Conda 4.7如何在bash脚本中激活env_Bash_Shell_Anaconda_Conda - Fatal编程技术网

Conda 4.7如何在bash脚本中激活env

Conda 4.7如何在bash脚本中激活env,bash,shell,anaconda,conda,Bash,Shell,Anaconda,Conda,我可以在我的外壳中激活我的环境 > conda activate env 在bash脚本中,我可以检查conda的版本,但无法激活env #!/bin/bash conda --version > conda 4.7.12 conda activate env > CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. To initialize

我可以在我的外壳中激活我的环境

> conda activate env
在bash脚本中,我可以检查conda的版本,但无法激活env

#!/bin/bash

conda --version
> conda 4.7.12

conda activate env
> 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'.
我从这里发现:我可以在激活我的环境之前添加到我的bash脚本中:

source /work/***/miniconda3/etc/profile.d/conda.sh
它可以工作(我的env已激活),但我不想在所有bash脚本开始时添加这一行,因为我的
.bashrc
中已经有了这一行。从这里我还发现:当我使用

bash -i shell_script.sh
它也在工作(我的环境被激活)


如何在每次运行脚本时自动生成
.bashrc
,而不在每个脚本中添加行,也不添加
-I
?例如,我可以用我的
.bashrc\u配置文件
执行此操作吗?

当运行bash脚本时,它通常不会生成.bashrc源代码,除非您使用
-I
脚本。这就是为什么
bash-i
有效。请看一下bash手册页,其中描述了在什么情况下bash会自动获取哪些文件。您可以添加。~/。我已经知道为什么
-i
可以工作了,我只是对这个解决方案不满意。添加
~/.bashrc
只是执行与
bash-i shell_script.sh
相同操作的另一种方法,我不想在每个脚本中添加一行。我在文章末尾添加了Eddite,以便您了解我想要的解决方案。
~/.bash_profile
仅在以交互登录模式启动时由bash提供。您可以创建一个新的主脚本,在其中运行
env activate脚本
,然后调用所需的最终脚本。好的,我明白为什么不能使用
.bash\u profile
来解决此问题。一个主脚本可以是一个解决方案,即使我跳的东西更好。糟糕的是,Conda变成了bash函数,不再是可执行文件。当您运行bash脚本时,它通常不会源代码.bashrc,除非您使用
-i
脚本。这就是为什么
bash-i
有效。请看一下bash手册页,其中描述了在什么情况下bash会自动获取哪些文件。您可以添加。~/。我已经知道为什么
-i
可以工作了,我只是对这个解决方案不满意。添加
~/.bashrc
只是执行与
bash-i shell_script.sh
相同操作的另一种方法,我不想在每个脚本中添加一行。我在文章末尾添加了Eddite,以便您了解我想要的解决方案。
~/.bash_profile
仅在以交互登录模式启动时由bash提供。您可以创建一个新的主脚本,在其中运行
env activate脚本
,然后调用所需的最终脚本。好的,我明白为什么不能使用
.bash\u profile
来解决此问题。一个主脚本可以是一个解决方案,即使我跳的东西更好。糟糕的是,Conda变成了bash函数,不再是可执行文件。
bash -i shell_script.sh