💭

vscodeで編集したjupyternotebookのexportエラー対処法

2022/12/31に公開約2,700字

事象

  • vscode上で編集したnotebookをPDFでexportしようとしたところ下記のエラーが発生。
> /opt/anaconda3/bin/python -m jupyter nbconvert /tmp/2039761f-2452-48f4-a2b9-fe06cfd385e4/work.1.ipynb --to pdf --output tmp-239FhAqS20h2565.html --output-dir /tmp --debug
error 12:46:37.424: Export failed [Error: [NbConvertApp] Searching ['/root/.vscode-server/bin/e8a3071ea4344d9d48ef8a4df2c097372b0c5161', '/root/.jupyter', '/opt/anaconda3/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files
[NbConvertApp] Looking for jupyter_config in /etc/jupyter
[NbConvertApp] Looking for jupyter_config in /usr/local/etc/jupyter
[NbConvertApp] Looking for jupyter_config in /opt/anaconda3/etc/jupyter
[NbConvertApp] Looking for jupyter_config in /root/.jupyter
[NbConvertApp] Looking for jupyter_config in /root/.vscode-server/bin/e8a3071ea4344d9d48ef8a4df2c097372b0c5161
[NbConvertApp] Looking for jupyter_nbconvert_config in /etc/jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /usr/local/etc/jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /opt/anaconda3/etc/jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /root/.jupyter
[NbConvertApp] Looking for jupyter_nbconvert_config in /root/.vscode-server/bin/e8a3071ea4344d9d48ef8a4df2c097372b0c5161
[NbConvertApp] Converting notebook /tmp/2039761f-2452-48f4-a2b9-fe06cfd385e4/work.1.ipynb to html
[NbConvertApp] Notebook name is 'tmp-239FhAqS20h2565'
[NbConvertApp] ERROR | Notebook JSON is invalid: Non-unique cell id '99b3287b-2872-4144-a7c1-e30e0ba29a5c' detected. Corrected to '93b153e5'.
〜〜〜中略〜〜〜
error 12:55:35.573: If you have not installed xelatex (TeX) you will need to do so before you can export to PDF, for further instructions please look https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex. 
To avoid installing xelatex (TeX) you might want to try exporting to HTML and using your browsers "Print to PDF" feature.

原因

  • 別のnotebookをコピーして編集していたことで、cell idがuniqueでなくなることが原因とのこと。

解消方法

  • 別のnotebookをコピーするのをやめるか、新しくnotebookを作成して、そこにコピペすることで解決する。

ソース

https://github.com/jupyter/notebook/issues/6001

https://stackoverflow.com/questions/66746193/notebook-validation-failed-jupyter

ハマったこと

  • PDFでexportしようとすると、以下のエラーでる。
error 12:55:35.573: If you have not installed xelatex (TeX) you will need to do so before you can export to PDF, for further instructions please look https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex. 
To avoid installing xelatex (TeX) you might want to try exporting to HTML and using your browsers "Print to PDF" feature.
  • xelatexのinstallを促されるので、再インストールしたりとめちゃくちゃハマった。
  • エラーをよく読めば、最初の方で'Notebook JSON is invalid: Non-unique cell id'が出てるので、最後のエラーと関係ないところを疑うべきで、落ち着いてエラー読もうねと思った。
  • issueはたてられてるようなので、最新バージョンでは解消しているかもしれない。

以上

Discussion

ログインするとコメントできます