加载自定义 conda env 在 SageMaker 中不起作用

Con*_*sis 12 python amazon-web-services conda jupyter-lab amazon-sagemaker

我已miniconda在我的 AWS SageMaker 持久 EBS 实例上安装。这是我的起始脚本:

#!/bin/bash

set -e

# OVERVIEW
# This script installs a custom, persistent installation of conda on the Notebook Instance's EBS volume, and ensures
# that these custom environments are available as kernels in Jupyter.
# 
# The on-start script uses the custom conda environment created in the on-create script and uses the ipykernel package
# to add that as a kernel in Jupyter.
#
# For another example, see:
# https://docs.aws.amazon.com/sagemaker/latest/dg/nbi-add-external.html#nbi-isolated-environment

sudo -u ec2-user -i <<'EOF'
unset SUDO_UID
WORKING_DIR=/home/ec2-user/SageMaker/

for env in $WORKING_DIR/miniconda/envs/*; do
    BASENAME=$(basename "$env")
    source "$WORKING_DIR/miniconda/bin/activate"
    source activate "$BASENAME"
    pip install ipykernel boto3
    python -m ipykernel install --user --name "$BASENAME" --display-name "Custom ($BASENAME)"
done
# Optionally, uncomment these lines to disable SageMaker-provided Conda functionality.
# echo "c.EnvironmentKernelSpecManager.use_conda_directly = False" >> /home/ec2-user/.jupyter/jupyter_notebook_config.py
# rm /home/ec2-user/.condarc
EOF

echo "Restarting the Jupyter server.."
restart jupyter-server
Run Code Online (Sandbox Code Playgroud)

我用它来加载我的自定义环境。然而,当我访问 JupyterLab 界面时,即使我看到激活的内核是自定义内核,我的笔记本内核上运行的唯一 python 版本是/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python

在此输入图像描述

我还检查了 CloudWatch 日志,并看到以下错误日志:Could not find conda environment: [custom_env]

但是,当我在 JupyterLab 终端中运行启动脚本的命令时,conda 成功找到了这些环境。所以问题是:我错过了什么?

多谢。

Ban*_*omi 2

创建预加载内核的自定义 SageMaker 映像https://docs.aws.amazon.com/sagemaker/latest/dg/studio-byoi.html

  • 底部有一条注释,基本上解释了您的问题“我们无法保证软件包安装会成功。尝试在具有不兼容依赖项的环境中安装包可能会导致失败......`我建议采用自定义 SageMaker Image 路线 (2认同)