Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

nbconvert - Unable to use exporters from jupyter nbcontrib_extensions

Using this Dockerfile:

FROM python:3.7
FROM jupyter/minimal-notebook
WORKDIR $HOME
RUN python -m pip install --upgrade pip
COPY requirements.txt ./requirements.txt
RUN python -m pip  install -r requirements.txt
RUN python -m pip install --upgrade --no-deps --force-reinstall notebook
#
RUN python -m pip install jupyterthemes
RUN python -m pip install --upgrade jupyterthemes
RUN python -m pip install jupyter_contrib_nbextensions
RUN jupyter contrib nbextension install --user
RUN jupyter nbextensions_configurator enable --user

# enable the Nbextensions
RUN jupyter nbextension enable contrib_nbextensions_help_item/main
RUN jupyter nbextension enable execute_time/ExecuteTime 
RUN jupyter nbextension enable codefolding/main
RUN jupyter nbextension enable collapsible_headings/main
RUN jupyter nbextension enable hide_input/main 
RUN jupyter nbextension enable toc2/main
RUN jupyter nbextension enable varInspector/main

When using the notebook, the extensions work (i have a toc, collapsible headings work etc) but when I try to export using those exporters (after docker exec..) I get errors

$ jupyter nbconvert --to html_ch test.ipynb --output test.html
--> jinja2.exceptions.TemplateNotFound: inliner

$ jupyter nbconvert --to html_toc test.ipynb --output test.html
--> jinja2.exceptions.TemplateNotFound: toc

Running `jupyter --paths:

config:
    /home/jovyan/.jupyter
    /opt/conda/etc/jupyter
    /usr/local/etc/jupyter
    /etc/jupyter
data:
    /home/jovyan/.local/share/jupyter
    /opt/conda/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter
runtime:
    /home/jovyan/.local/share/jupyter/runtime

And in .jupyter/jupyter_nbconvert_config.json I have this:

{
  "version": 1,
  "Exporter": {
    "template_path": [
      ".",
      "/opt/conda/lib/python3.8/site-packages/jupyter_contrib_nbextensions/templates",
    ],
    "preprocessors": [
      "jupyter_contrib_nbextensions.nbconvert_support.CodeFoldingPreprocessor",
      "jupyter_contrib_nbextensions.nbconvert_support.PyMarkdownPreprocessor"
    ]
  }
}

Listing the templates path above I see the templates there:

ls /opt/conda/lib/python3.8/site-packages/jupyter_contrib_nbextensions/templates
collapsible_headings.tpl  highlighter.tplx  nbextensions.tpl   printviewlatex.tplx
highlighter.tpl           inliner.tpl       nbextensions.tplx  toc2.tpl

so not sure what's missing in my Dockerfile.

If I run this jupyter nbconvert --to html test.ipynb --output test.html --template toc2 I get another error:

ValueError: No template sub-directory with name 'toc2' found in the following paths:
        /home/jovyan/.local/share/jupyter
        /opt/conda/share/jupyter
        /usr/local/share/jupyter
        /usr/share/jupyter

Any ideas?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...