Last active
November 18, 2025 23:55
-
-
Save drscotthawley/e6927f1389f262ecbabfe41d31989e1c to your computer and use it in GitHub Desktop.
fixes up jupyter notebook widgets state so GitHub can visualize notebooks again
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Usage: python fix_notebook.py <.ipynb file> | |
| # WARNING: this overwrites the file, so save a backup first | |
| # To execute on a whole folder of files, run this bash command: | |
| # find . -name "*.ipynb" -exec python fix_notebook.py {} \; | |
| import json | |
| import sys | |
| def fix_notebook(filename): | |
| with open(filename, 'r') as f: | |
| nb = json.load(f) | |
| # Remove metadata.widgets entirely (safest approach) | |
| if 'metadata' in nb and 'widgets' in nb['metadata']: | |
| del nb['metadata']['widgets'] | |
| with open(filename, 'w') as f: | |
| json.dump(nb, f, indent=2) | |
| print(f"Fixed {filename}") | |
| # Usage: python fix_notebook.py notebook.ipynb | |
| if __name__ == "__main__": | |
| fix_notebook(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment