bash - Conda 4.7 如何在 bash 脚本中激活 env
问题描述
我可以在我的 shell 中激活我的环境
> conda activate env
当我在 bash 脚本中时,我可以检查我的 conda 的版本,但我无法激活我的环境
#!/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'.
这是我.bashrc
关于 conda 初始化的内容
8 # User specific aliases and functions
9
10 # >>> conda initialize >>>
11 # !! Contents within this block are managed by 'conda init' !!
12 __conda_setup="$('/work/***/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
13 if [ $? -eq 0 ]; then
14 eval "$__conda_setup"
15 else
16 if [ -f "/work/***/miniconda3/etc/profile.d/conda.sh" ]; then
17 . "/work/***/miniconda3/etc/profile.d/conda.sh"
18 else
19 export PATH="/work/***/miniconda3/bin:$PATH"
20 fi
21 fi
22 unset __conda_setup
23 # <<< conda initialize <<<
我从这里找到:Conda 命令在命令提示符下工作,但不在 bash 脚本中,我可以在激活我的 env 之前将其添加到我的 bash 脚本中:
source /work/***/miniconda3/etc/profile.d/conda.sh
它可以工作(我的环境已激活),但我不想在所有 bash 脚本的开头添加这一行,因为我的.bashrc
. 我还从这里找到:Python - 通过 shell 脚本激活 conda env.bashrc
,当我运行我的脚本时,我可以使用它
bash -i shell_script.sh
它也在工作(我的环境已激活)。
如何.bashrc
在每次运行脚本时自动获取源代码而不在每个脚本中添加一行且不添加-i
?我可以用我.bashrc_profile
的例子来做这个吗?
解决方案
推荐阅读
- r - R:在给定两个条件的情况下替换两个 data.frames 之间的值,而不更改不匹配项
- python - Python和Selenium根据同一行中的另一个td单击一行中的td值
- apache-kafka - 如何从 Apache Nifi 中上次提交的偏移量读取消费者中的 Kafka 消息?
- sql - 选择联合计数和组,多个表,postgresql
- javascript - Loopback 扩展用户模型抛出 TypeError: Cannot convert undefined or null to object
- android - Cordova 构建失败并出现异常:无法解析 com.android.tools.build:gradle:3.0.0
- ubuntu - 在 Ubuntu 18.04 NGINX 上运行的 ASP .NET Core 网站:可能存在缓存问题
- ruby-on-rails - 未初始化常量:Prawn
- arrays - 根据employeeid设置标题
- c++ - C++ 最佳实践:在多个 .cpp 文件中编写类方法的定义