I want to import certain libraries and define certain functions in my first cell of the notebook every time it starts. In my case, I am using a Docker container for this purpose. After going through several links and answers( https://vivekbharadwaj.github.io/data%20science/jumpstart-your-Jupyter-notebook-analysis-with-pre-loaded-cells/ ), I am unable to set the notebook up as I have certain errors.
These are the commands:
# 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
With the current similar answers and questions, I am unable to have my configuration either due to error or because ipython
is used.
While running, I get the following error on this step:
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
我在这里使用了另一种特定于ipython
方法( https://stackoverflow.com/a/56216780/10834788 )。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.