我已经在我的AWS SageMaker永久EBS实例上安装了miniconda
。这是我的起始脚本:
#!/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
我使用这个方法来加载我的自定义环境。然而,当我访问JupyterLab界面时,即使我看到激活的内核是自定义的,但在我的笔记本内核中运行的Python版本只有/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python
:
我还检查了CloudWatch日志,并看到此错误日志:Could not find conda environment: [custom_env]
。
但是,当我在JupyterLab终端中运行启动脚本的命令时,conda可以成功找到这些环境。那么问题来了:我漏掉了什么?
非常感谢。
%
代替时,就没有这个问题了。然而,我仍然无法在Jupyter笔记本中运行通过conda安装的非Python包。 - Brad English