笔记本验证失败 Jupyter

Notebook validation failed Jupyter

这不是 Notebook Validation Failed 的副本。

我有一个 Jupyter ntb,它直到最近都运行良好。无论我做什么,我都会遇到那些正在发生变化的错误(我附上了一些例子)并且我对 ntb 做了什么并不重要(我尝试重新启动内核,重新启动 Jupyter)。此外,它只发生在这个 ntb 中,即使 运行 同时来自同一会话,也不会发生在其他人中。我试图搜索但找不到任何东西。我在 Jupyter 中得到的是:

其中有很多,相似但不同:

The save operation succeeded, but the notebook does not appear to be valid. The validation error was:
Notebook validation failed: Non-unique cell id 'geological-poker' detected. Corrected to 'front-hampshire'.:
"<UNKNOWN>"

或其他人:

Notebook validation failed: Non-unique cell id 'medieval-nebraska' detected. Corrected to 'stock-eating'.:
"<UNKNOWN>"
Notebook validation failed: Non-unique cell id 'intense-award' detected. Corrected to 'blocked-garage'.:
"<UNKNOWN>"

而我在终端中得到的是:

Notebook JSON is invalid: Non-unique cell id 'medieval-nebraska' detected. Corrected to 'convinced-vacation'.

Notebook JSON is invalid: Non-unique cell id 'medieval-nebraska' detected. Corrected to 'described-commerce'.
Notebook JSON is invalid: Non-unique cell id 'meaning-victoria' detected. Corrected to 'occasional-numbers'.
Notebook JSON is invalid: Non-unique cell id 'eastern-buyer' detected. Corrected to 'english-benchmark'.

知道发生了什么以及如何解决它吗?


更新: 它以某种方式修复了一段时间,但后来又开始做同样的事情,我仍然不明白它是什么以及它是如何修复和再次毁坏的……一种解决方法是复制一份 ntb,然后丢弃旧的.


更新 9.10.21:

pythonv3.8.11看来这已经不是问题了。自更新所有软件包以来,我还没有设法重现该问题,因此现在最简单的解决方法可能是更新。我有:

jupyter core     : 4.7.1
jupyter-notebook : 6.4.3
ipython          : 7.26.0
ipykernel        : 6.2.0

我遇到了同样的问题,在阅读之后,似乎是 copy/pasting 个来自其他会话中创建的其他笔记本的单元格。我还没有找到修复它的方法,但至少你可以通过复制单元格的内容而不是单元格本身来防止它发生。

用于重新保存已解决单元名称问题的笔记本的代码:

import nbformat as nbf
from glob import glob

import uuid
def get_cell_id(id_length=8):
    return uuid.uuid4().hex[:id_length]

# -- SETUP
nb_name = 'my_notebook'

# -- MAIN
# grab notebook
notebooks = list(filter(lambda x: nb_name in x, glob("./*.ipynb", recursive=True)))

# iterate over notebooks
for ipath in sorted(notebooks):
    # load notebook
    ntbk = nbf.read(ipath, nbf.NO_CONVERT)
    
    cell_ids = []
    for cell in ntbk.cells:
        cell_ids.append(cell['id'])

    # reset cell ids if there are duplicates
    if not len(cell_ids) == len(set(cell_ids)): 
        for cell in ntbk.cells:
            cell['id'] = get_cell_id()

        nbf.write(ntbk, ipath)

我也碰巧找到了另一个有效的解决方案:

First select all the cells in the Jupyter Notebook, then press the "cut/scissors" button (don't panic, at this point your Notebook will be empty), and finally press the "paste" button.

这是来自https://github.com/jupyter/notebook/issues/6001#issuecomment-959828688.

简单回答

第一步: 使用剪刀剪掉Jupyter-notebook中的所有单元格 ] 选项如图所示。

第 2 步: 现在保存笔记本,然后使用粘贴选项粘贴上一步中剪切的单元格,如图所示。

第 3 步:再次保存,您的错误现在应该已修复!快点,快乐编码。