我想每次启动笔记本时在笔记本的第一个单元中导入某些库并定义某些功能。就我而言,我为此使用了一个Docker容器。经过几个链接和答案(https://vivekbharadwaj.github.io/data%20science/jumpstart-your-Jupyter-notebook-analysis-with-pre-loaded-cells/)之后,由于出现某些错误,我无法设置笔记本。
这些是命令:
# Python3 Kernel for JuPyter notebooks
RUN python3 -m pip install ipykernel
RUN python3 -m ipykernel install --user
RUN python3 -m pip install jupyter_contrib_nbextensions
RUN mkdir -p /usr/local/airflow/.local/share/jupyter/preload_import_code
RUN echo "define([ 'base/js/namespace' ], function( Jupyter ) { function load_ipython_extension() { if (Jupyter.notebook.get_cells().length===1){ //change this piece of code to what you want Jupyter.notebook.insert_cell_above('code', 0).set_text(\"import os, sys;\"); } } return { load_ipython_extension: load_ipython_extension }; });" >> /usr/local/airflow/.local/share/jupyter/preload_import_code/main.js
RUN jupyter nbextension enable --sys-prefix preload_import_code/main
使用当前类似的答案和问题,由于错误或由于使用了ipython
,我无法进行配置。
在运行时,此步骤出现以下错误:
Step 36/41 : RUN jupyter nbextension enable --sys-prefix preload_import_code/main
---> Running in c56e28731e36
Enabling notebook extension preload_import_code/main...
- Validating: problems found:
- require? X preload_import_code/main
Removing intermediate container c56e28731e36
---> ea0c6505dd57