title: Loading custom conda envs not working in SageMaker
body: <p>I have installed <code>miniconda</code> on my AWS SageMaker persistent EBS instance. Here is my starting script:</p>
  <pre class="lang-sh prettyprint-override"><code>#!/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 &lt;&lt;'EOF'
  unset SUDO_UID
  WORKING_DIR=/home/ec2-user/SageMaker/
  
  for env in $WORKING_DIR/miniconda/envs/*; do
      BASENAME=$(basename &quot;$env&quot;)
      source &quot;$WORKING_DIR/miniconda/bin/activate&quot;
      source activate &quot;$BASENAME&quot;
      pip install ipykernel boto3
      python -m ipykernel install --user --name &quot;$BASENAME&quot; --display-name &quot;Custom ($BASENAME)&quot;
  done
  # Optionally, uncomment these lines to disable SageMaker-provided Conda functionality.
  # echo &quot;c.EnvironmentKernelSpecManager.use_conda_directly = False&quot; &gt;&gt; /home/ec2-user/.jupyter/jupyter_notebook_config.py
  # rm /home/ec2-user/.condarc
  EOF
  
  echo &quot;Restarting the Jupyter server..&quot;
  restart jupyter-server
  </code></pre>
  <p>I use this in order to load my custom envs. However, when I access the JupyterLab interface, even if I see that the activated kernel is the Custom one, the only version of python running on my notebook kernel is <code>/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python</code>:</p>
  <p><a href="https://i.stack.imgur.com/yHOnG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yHOnG.png" alt="enter image description here" /></a></p>
  <p>I also inspected the CloudWatch logs, and I see this error log: <code>Could not find conda environment: [custom_env]</code>.</p>
  <p>But, when I run the commands of the starting script within the JupyterLab terminal, conda succeeds in finding those envs. So the question is: what am I missing?</p>
  <p>Thanks a lot.</p>