nbconvert: "KeyError: 'state'" when trying to convert a notebook from Google Colab
Hello,
I seem to every so often get the following error:
File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/nbconvert/filters/widgetsdatatypefilter.py", line 56, in __call__
[95](https://github.com/mrdbourke/pytorch-deep-learning/runs/5597148101?check_suite_focus=true#step:8:95)
metadata['widgets'][WIDGET_STATE_MIMETYPE]['state'] if
[96](https://github.com/mrdbourke/pytorch-deep-learning/runs/5597148101?check_suite_focus=true#step:8:96)
KeyError: 'state'
[97](https://github.com/mrdbourke/pytorch-deep-learning/runs/5597148101?check_suite_focus=true#step:8:97)
Error: Process completed with exit code 1.
It seems to be most often when I’m saving a notebook from Google Colab into GitHub and then running a GitHub Action to convert it directly into documentation.
The GitHub Action traceback can be seen here: https://github.com/mrdbourke/pytorch-deep-learning/runs/5597148101?check_suite_focus=true
The notebook in question can be found here: https://github.com/mrdbourke/pytorch-deep-learning/blob/main/03_pytorch_computer_vision.ipynb
The issue doesn’t occur on other notebooks converted in the same manner.
Things I’ve tried:
- Make a copy of the notebook, resave under same name (in Google Colab)
- Clone the notebook locally, rerun, save, commit
Both of these result in the same result as above.
Any help would be greatly appreciated, I’m not quite sure where this error is coming from nor why it happens to some notebooks and not others.
To the best of my knowledge, the notebook it happens on “03_pytorch_computer_vision.ipynb” uses the exact same style as other notebooks (Python code and markdown).
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 10
- Comments: 15 (1 by maintainers)
Thanks
“Widgets” --> “Clear Notebook Widgets State” helped me in jupyter
Dumb workaround for without access to CLI jq and without reuploading to Colab:
JSON
fielddel(.metadata.widgets)
into filter pane (Thanks @hs211216)Result
fieldWorks now.
Just hit with https://colab.research.google.com/github/kstathou/vector_engine/blob/master/notebooks/001_vector_search.ipynb
The workaround recommended by @pplonski worked for me. Here is what I did
Download 001_vector_search.ipynb with Colab gui
Fail to convert it with nbconvert
For reference I’m on OSX 10.15.7 and here are my jupyter versions
Remove
metadata/widgets
in notebook file.Notes: If you are unable to locate the Widget tab on your notebook, which happened to me as well, you will need to install
ipywidgets
by executing the following command and restart your notebook.Update 2 Feb 2024:
You may need to install
nbclassic
to the get the widget item in the menu bar, see: https://github.com/jupyter/nbclassicInstall:
Run:
Otherwise clearing the widget metadata as discussed above may work too, however, I’m not 100% sure.