GCP 在启动脚本上安装 conda

问题描述 投票:0回答:1

我尝试在虚拟机首次启动时安装 conda,但遇到一个又一个错误。 启动脚本如下:

#!/bin/bash -i
sleep 5
yes Y | sudo apt-get update

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -P /home/user/
bash /home/user/Miniconda3-latest-Linux-x86_64.sh -b
rm /home/user/Miniconda3-latest-Linux-x86_64.sh  
/home/user/miniconda3/bin/conda init bash
source /home/user/miniconda3/etc/profile.d/conda.sh
eval "$(cat /home/user/.bashrc | tail -n +10)"

yes Y | conda create -n test python=3.8

conda activate test

如果我直接运行上面的代码,它就可以正常工作。但是,当它作为启动脚本运行时,我会在日志中看到以下内容:

Aug 29 15:49:51 testconda google_metadata_script_runner[850]: startup-script: /home/user/Miniconda3-latest-Linux-x86_64.sh: line 29: HOME: unbound variable
Aug 29 15:49:51 testconda google_metadata_script_runner[850]: startup-script: bash: /home/user/miniconda3/bin/conda: No such file or directory
Aug 29 15:49:51 testconda google_metadata_script_runner[850]: startup-script: bash: /home/user/miniconda3/etc/profile.d/conda.sh: No such file or directory
Aug 29 15:49:51 testconda google_metadata_script_runner[850]: startup-script: bash: conda: command not found
Aug 29 15:49:51 testconda google_metadata_script_runner[850]: startup-script: bash: conda: command not found
Aug 29 15:49:51 testconda google_metadata_script_runner[850]: startup-script exit status 127
Aug 29 15:49:51 testconda google_metadata_script_runner[850]: Finished running startup scripts.

有人可以帮忙吗?在 GCP 中制作正确的启动脚本确实很困难。

google-cloud-platform google-compute-engine startup
1个回答
0
投票

经过多次尝试和错误,我在这里找到了答案: 在 EC2 实例中安装 Miniconda 时,Boto3 UserData 脚本对 $HOME 变量有意外行为

以下启动脚本有效! (user是我的用户名)

#!/bin/bash

sudo -u user bash <<EOF
cd /home/user/

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda3.sh 2> log_miniconda
bash /tmp/miniconda3.sh -b -p /home/user/miniconda3 2> log_minicondash

/home/user/miniconda3/bin/conda init bash
source /home/user/miniconda3/etc/profile.d/conda.sh
source /home/user/.bashrc

conda create -y -n test python=3.8

conda activate test
EOF
© www.soinside.com 2019 - 2024. All rights reserved.