Created
November 16, 2021 17:12
-
-
Save Gcav66/ea259a32d7102833c8d74904e0c573b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/custom-miniconda/ | |
source "$WORKING_DIR/miniconda/bin/activate" | |
for env in $WORKING_DIR/miniconda/envs/*; do | |
BASENAME=$(basename "$env") | |
source activate "$BASENAME" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment