1
votes

There's probably something very obvious I'm missing or Sagemaker just doesn't support these kinds of extensions, but I've been trying to enable toc2 (Table of Contents) jupyter extension for my Sagemaker notebook via lifecycle configurations, but for whatever reason it still isn't showing up.

I built my script out combining a sample AWS script and a quick article on the usual ways of enabling extensions:

https://github.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/blob/master/scripts/install-nb-extension/on-start.sh

https://towardsdatascience.com/jupyter-notebook-extensions-517fa69d2231

#!/bin/bash

set -e
sudo -u ec2-user -i <<EOF

--Activate notebook environment
source activate JupyterSystemEnv

--Install extensions
pip install jupyter_contrib_nbextensions && jupyter contrib
nbextension install
jupyter nbextension enable toc2 --py --sys-prefix

source deactivate


EOF

Thanks!

2
I encountered the same issue. Have you by any change found a solution? Thanks! - Mark Wang
Hey @MarkWang, ultimately didn't keep pursuing, however Jupyter Lab by default has TOC functionality built in so I've been using that more. - Ben Saunders

2 Answers

1
votes

Maybe you need to restart the Jupyter process after installing the extension:

#!/bin/bash

set -e
sudo -u ec2-user -i <<EOF

--Activate notebook environment
source activate JupyterSystemEnv

--Install extensions
pip install jupyter_contrib_nbextensions && jupyter contrib
nbextension install
jupyter nbextension enable toc2 --py --sys-prefix

source deactivate

EOF

initctl restart jupyter-server --no-wait
1
votes

Answering my question, looks like I was just missing the line jupyter contrib nbextension install --user to copy the JS/CSS files into Jupyter's search directory and some config updates (https://github.com/ipython-contrib/jupyter_contrib_nbextensions).

Corrected statement

#!/bin/bash

set -e
sudo -u ec2-user -i <<'EOF'

source /home/ec2-user/anaconda3/bin/activate JupyterSystemEnv

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextension enable toc2/main

source /home/ec2-user/anaconda3/bin/deactivate


EOF

##Below may be unnecessary, but other user needed to run to see success
initctl restart jupyter-server --no-wait