无法为 AWS Sagemaker 实例(生命周期配置)安装 toc2 笔记本扩展

Unable to install toc2 notebook extension for AWS Sagemaker Instance (Lifecycle Configurations)

可能我遗漏了一些非常明显的东西,或者 Sagemaker 只是不支持这些类型的扩展,但我一直在尝试为我的 Sagemaker 笔记本启用 toc2(Table of Contents)jupyter 扩展通过生命周期配置,但无论出于何种原因,它仍然没有出现。

我结合了一个示例 AWS 脚本和一篇关于启用扩展的常用方法的快速文章构建了我的脚本:

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

谢谢!

安装扩展后可能需要重启Jupyter进程:

#!/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

回答我的问题,看起来我只是缺少行 jupyter contrib nbextension install --user 将 JS/CSS 文件复制到 Jupyter 的搜索目录和一些配置更新 (https://github.com/ipython-contrib/jupyter_contrib_nbextensions)。

更正语句

#!/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

我使用此代码为我工作

pkill -f jupyter-notebook

而不是

initctl restart jupyter-server --no-wait