作为管道的一部分,我正在AWS上构建构建服务器。我正在使用一个buildspec文件,该文件使用镜像(aws / codebuild / amazonlinux2-x86_64-standard:2.0)将我的代码复制到linux实例后运行以下命令:
- echo 'Install Conda to run python'
- echo 'Download conda from web'
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
- echo 'Install miniconda'
- sh ~/miniconda.sh -b -p $HOME/miniconda
- eval "$(~/miniconda/bin/conda shell.bash hook)"
- echo 'cd to outbound and list'
- cd outbound
- echo 'create conda environment'
- conda env create -f environment_droplet.yml
- conda env list
- bash
- conda init bash
- echo "conda activate calme" >> ~/.bash_profile
- echo ". ~/miniconda/etc/profile.d/conda.sh" >> ~/.bash_profile
- echo "export PATH=~/miniconda/bin:$PATH" >> ~/.bash_profile
- . ~/.bash_profile
- exec bash
- conda init bash
- conda activate calme
但是,最后一个命令'conda activate不成功,并导致错误:
[Container] 2020/08/30 20:38:14 Running command conda init bash
no change /root/miniconda/condabin/conda
no change /root/miniconda/bin/conda
no change /root/miniconda/bin/conda-env
no change /root/miniconda/bin/activate
no change /root/miniconda/bin/deactivate
no change /root/miniconda/etc/profile.d/conda.sh
no change /root/miniconda/etc/fish/conf.d/conda.fish
no change /root/miniconda/shell/condabin/Conda.psm1
no change /root/miniconda/shell/condabin/conda-hook.ps1
no change /root/miniconda/lib/python3.8/site-packages/xontrib/conda.xsh
no change /root/miniconda/etc/profile.d/conda.csh
no change /root/.bashrc
No action taken.
[Container] 2020/08/30 20:38:14 Running command conda activate calme
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'.
[Container] 2020/08/30 20:38:14 Command did not exit successfully conda activate calme exit status 1
[Container] 2020/08/30 20:38:14 Phase complete: PRE_BUILD State: FAILED
[Container] 2020/08/30 20:38:14 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: conda activate calme. Reason: exit status 1
如您所见,从我的buildspec片段中,我正在重新加载.bash_profile,应用conda init bash并创建一个新的bash实例。我相信以上所有命令都会帮助重置现有终端,因此conda activate是一个公认的命令-事实并非如此。 创建独立的EC2实例时,我没有此问题,因为我可以重新启动终端/关闭连接并重新连接。但是,我需要能够通过buildspec和为项目构建而创建的ec2实例激活conda。感谢您的帮助