添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

jupyter nbconvert --to html_toc not working (convert jupyter notebook with table of content to website format)

Ask Question

What I wanted

With the nbextension toc , jupyter notebooks have table of content capabilities which is said to be transferable to html via nbconvert --to html_toc function , or via the dropdown menue "download as html with toc". However, neither option works in my case.

What I have tried

  • Download as html with toc initially gave an error similar to TemplateNotFound: toc2
  • All recommended commands like jupyter nbconvert FILE.ipynb --template toc jupyter nbconvert FILE.ipynb --template toc2 (These two appear to be incomplete but are supplied like this) jupyter nbconvert --to html_toc FILE.ipynb (same error as above via menue)
  • As here and here the toc2.tpl file is mentioned, I placed this file together with the main.css and toc2.js file into the same directory as the ipynb notebook to be converted. Now the download as html with toc menue gives error "nbconvert failed: toc2" and the jupyter nbconvert FILE.ipynb --template toc2 gives error "jinja2.exceptions.TemplateNotFound: toc2" I still have not understood the role of the toc2 template. Is it (still) necessary? Why? How (with the other files?)? Where (how is the location provided)? What exactly is needed where and how to make use of this extremely usefull functionality?
  • The downgrade mentioned here was not possible due to resulting incompab.
  • Used Conditions / Versions in conda virtual environment

    (Please tell me if you need more information)

    jupyter core     : 4.7.1
    jupyter-notebook : 6.2.0
    qtconsole        : 5.0.2
    ipython          : 7.20.0
    ipykernel        : 5.3.4
    jupyter client   : 6.1.7
    jupyter lab      : 3.0.8
    nbconvert        : 6.0.7
    ipywidgets       : 7.6.3
    nbformat         : 5.1.2
    traitlets        : 5.0.5
                    I don't know if my problem is related, but I was missing html as an available format in nbconvert --execute, and papermill was also producing garbage (the original .ipynb JSON, as it seemed). It could have something to do with Python 3.9 - I switched to an older Conda env at Python 3.7, and the conversion to HTML was working. I think it's a bug that will go away some time in the future.
    – Tomasz Gandor
                    Apr 15, 2021 at 17:40
                    @XopiGarcía Thank you for asking but I have not followed this further. Not important enough at the moment :)
    – le8rning
                    Feb 20, 2022 at 14:55
                    No posible solution for him, as he said: 4. The downgrade mentioned here was not possible due to resulting incompab.
    – Xopi García
                    Dec 27, 2021 at 16:19
    

    Then check that it installed nbconvert-5.6.1 (5.6.1 version).

    After that, execute the following:

    jupyter nbconvert --to html_toc YOURFILENAME.ipynb
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.