简体   繁体   English

如何在不使用ipython的情况下配置jupyter笔记本以使用某些导入来预加载单元格?

[英]How do I configure jupyter notebook for having a pre loaded cell with certain imports without using ipython?

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. 就我而言,我为此使用了一个Docker容器。 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. 经过几个链接和答案( https://vivekbharadwaj.github.io/data%20science/jumpstart-your-Jupyter-notebook-analysis-with-pre-loaded-cells/ )后,我无法设置笔记本因为我有某些错误。

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. 使用当前类似的答案和问题,由于错误或因为使用了ipython ,我无法进行配置。

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 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在浏览器中增加 Jupyter/ipython 笔记本的单元格宽度? - How do I increase the cell width of the Jupyter/ipython notebook in my browser? 如何在 IPython (Jupyter) Notebook 的远程机器上添加 kernel? - How do I add a kernel on a remote machine in IPython (Jupyter) Notebook? 如何从 IPython shell 执行 Jupyter notebook? - How do I execute a Jupyter notebook from an IPython shell? 如何设置ipython jupyter笔记本的单元格? - How do I cron an ipython jupyter notebook's cells? 如何获取当前的 IPython / Jupyter Notebook 名称 - How do I get the current IPython / Jupyter Notebook name 在 Jupyter Notebook 中使用 ipython-sql 时,如何创建自定义 Sqlite UDF? - How do I create a custom Sqlite UDF while using ipython-sql in a Jupyter Notebook? 如何增加Enthought Canopy中ipython笔记本的单元格宽度? - How do I increase the cell width of the ipython notebook in Enthought Canopy? 如何同时捕获和显示 ipython (jupyter notebook) 单元格输出? - How to simultaneously capture and display ipython (jupyter notebook) cell output? 如何在ipython / jupyter笔记本单元格中设置图片显示位置? - How to set picture display location in ipython/jupyter notebook cell? 导出单个iPython Jupyter Notebook单元格输出 - Exporting single iPython Jupyter Notebook cell output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM