iPython笔记本错误 - Notebook JSON无效:u' execution_count'是必需的财产

时间:2015-12-04 10:04:08

标签: ipython-notebook

我在运行iPython笔记本时遇到以下错误,并且想知道是否有人可以提供帮助。

我曾尝试浏览以前的帖子,但无法找到答案。 noteboook最终在Web浏览器上运行,但错误仍然出现。

控制台出错:

C:\Apps\Anaconda2\envs\simpleQT\python.exe
C:\Apps\Anaconda2\envs\simpleQT\Scripts\ipython-script.py notebook --no-browser --ip 127.0.0.1 --port 8888
[I 09:43:20.525 NotebookApp] The port 8888 is already in use, trying another random port.
[I 09:43:20.528 NotebookApp] Serving notebooks from local directory: C:\Users\Tanya.Sandoval\_QT\simpleQT
[I 09:43:20.528 NotebookApp] 0 active kernels 
[I 09:43:20.528 NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8889/
[I 09:43:20.528 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[E 09:43:37.553 NotebookApp] Notebook JSON is invalid: u'execution_count' is a required property

Failed validating u'required' in schema:
    {u'additionalProperties': False,
     u'description': u'Result of executing a code cell.',
     u'properties': {u'data': {u'$ref': u'#/definitions/misc/mimebundle'},
                     u'execution_count': {u'description': u"A result's prompt number.",
                                          u'minimum': 0,
                                          u'type': [u'integer', u'null']},
                     u'metadata': {u'$ref': u'#/definitions/misc/output_metadata'},
                     u'output_type': {u'description': u'Type of cell output.',
                                      u'enum': [u'execute_result']}},
     u'required': [u'output_type',
                   u'data',
                   u'metadata',
                   u'execution_count'],
     u'type': u'object'}

On instance:
    {u'data': {u'text/html': u'<div>\n<table border="1" class="dataframe">\n  <thead>\n    <tr style="text-align: right;">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Volume</th>\n    </tr>\n    <tr>\n      <th>Timestamp</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2009-01-02</th>\n      <td>15.90</td>\n      <td>15.95</td>\n      <td>15.30</td>\n      <td>15.55</td>\n      <td>1065</td>\n    </tr>\n    <tr>\n      <th>2009-01-05</th>\n      <td>15.94</td>\n      <td>15.94</td>\n      <td>15.32</td>\n      <td>15.38</td>\n      <td>3710</td>\n    </tr>\n    <tr>\n      <th>2009-01-06</th>\n      <td>15.60</td>\n      <td>15.90</td>\n      <td>15.43</td>\n      <td>15.69</td>\n      <td>4619</td>\n    </tr>\n    <tr>\n      <th>2009-01-07</th>\n      <td>15.75</td>\n      <td>16.04</td>\n      <td>15.40</td>\n      <td>15.45</td>\n      <td>5956</td>\n    </tr>\n    <tr>\n      <th>2009-01-08</th>\n      <td>15.40</td>\n      <td>15.45</td>\n      <td>14.49</td>\n      <td>14.76</td>\n      <td>8454</td>\n    </tr>\n    <tr>\n      <th>2009-01-09</th>\n      <td>14.60</td>\n      <td>14.80</td>\n      <td>14.40</td>\n      <td>14.44</td>\n      <td>6846</td>\n    </tr>\n    <tr>\n      <th>2009-01-12</th>\n      <td>14.40</td>\n      <td>14.40</td>\n      <td>13.70</td>\n      <td>13.94</td>\n      <td>10355</td>\n    </tr>\n    <tr>\n      <th>2009-01-13</th>\n      <td>13.30</td>\n      <td>14.05</td>\n      <td>13.30</td>\n      <td>13.78</td>\n      <td>11341</td>\n    </tr>\n    <tr>\n      <th>2009-01-14</th>\n      <td>13.90</td>\n      <td>14.25</td>\n      <td>13.20</td>\n      <td>13.28</td>\n      <td>11170</td>\n    </tr>\n    <tr>\n      <th>2009-01-15</th>\n      <td>13.17</td>\n      <td>13.64</td>\n      <td>13.07</td>\n      <td>13.25</td>\n      <td>9745</td>\n    </tr>\n  </tbody>\n</table>\n</div>'},
     u'metadata': {},
     u'output_type': u'execute_result'}
[W 09:43:37.565 NotebookApp] Notebook notebook.ipynb is not trusted
[I 09:43:38.515 NotebookApp] Kernel started: c8c37658-b072-4a1d-87c5-0f862f514e44

网络浏览器出错:

Notebook Validation failed: u'execution_count' is a required property:
{
 "output_type": "execute_result", 
 "data": {
  "text/html": "<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Volume</th>\n    </tr>\n    <tr>\n      <th>Timestamp</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2009-01-02</th>\n      <td>15.90</td>\n      <td>15.95</td>\n      <td>15.30</td>\n      <td>15.55</td>\n      <td>1065</td>\n    </tr>\n    <tr>\n      <th>2009-01-05</th>\n      <td>15.94</td>\n      <td>15.94</td>\n      <td>15.32</td>\n      <td>15.38</td>\n      <td>3710</td>\n    </tr>\n    <tr>\n      <th>2009-01-06</th>\n      <td>15.60</td>\n      <td>15.90</td>\n      <td>15.43</td>\n      <td>15.69</td>\n      <td>4619</td>\n    </tr>\n    <tr>\n      <th>2009-01-07</th>\n      <td>15.75</td>\n      <td>16.04</td>\n      <td>15.40</td>\n      <td>15.45</td>\n      <td>5956</td>\n    </tr>\n    <tr>\n      <th>2009-01-08</th>\n      <td>15.40</td>\n      <td>15.45</td>\n      <td>14.49</td>\n      <td>14.76</td>\n      <td>8454</td>\n    </tr>\n    <tr>\n      <th>2009-01-09</th>\n      <td>14.60</td>\n      <td>14.80</td>\n      <td>14.40</td>\n      <td>14.44</td>\n      <td>6846</td>\n    </tr>\n    <tr>\n      <th>2009-01-12</th>\n      <td>14.40</td>\n      <td>14.40</td>\n      <td>13.70</td>\n      <td>13.94</td>\n      <td>10355</td>\n    </tr>\n    <tr>\n      <th>2009-01-13</th>\n      <td>13.30</td>\n      <td>14.05</td>\n      <td>13.30</td>\n      <td>13.78</td>\n      <td>11341</td>\n    </tr>\n    <tr>\n      <th>2009-01-14</th>\n      <td>13.90</td>\n      <td>14.25</td>\n      <td>13.20</td>\n      <td>13.28</td>\n      <td>11170</td>\n    </tr>\n    <tr>\n      <th>2009-01-15</th>\n      <td>13.17</td>\n      <td>13.64</td>\n      <td>13.07</td>\n      <td>13.25</td>\n      <td>9745</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
 }, 
 "metadata": {}
}

有什么想法吗?谢谢!

更新

实际上只有当我从PyCharm编辑器运行jupyter / ipython笔记本时才会出现此错误。如果我在网络浏览器上运行它,错误就会消失。看起来PyCharm的笔记本兼容性仍然存在漏洞......

3 个答案:

答案 0 :(得分:8)

在笔记本上使用PyCharm后我遇到了同样的问题。

我可以通过简单地重新启动内核,清除所有输出并保存笔记本来使错误在浏览器中消失。

重新启动内核是通过转到 Kernal 菜单,然后选择重新启动&amp;清除输出。查看屏幕截图的示例: enter image description here

答案 1 :(得分:0)

今天我遇到了同样的问题,当时我正在尝试编写一个脚本,对我的ipython脚本进行半自动编辑。

你可以在python中逐行读取文件,然后执行str.replace('“execution_count”:“null”','“execution_count”:null') 并将输出写入新文件。

然后您可以在ipython notebook中打开新文件。它解决了我的问题。毕竟,ipython笔记本文件只是一个json文件(只不过是一堆嵌套的词典和列表)。

答案 2 :(得分:0)

我在这个问题上失去了相当多的时间。如果所有其他方法都失败了,请将单元格转换为markdown(您可以在Pycharm中执行此操作),然后保存。

此时它应该在常规浏览器中打开,您可以将它们重新转换为代码。

如果您可以选择清除所有输出和保存,那就更容易了(在我的情况下,这不是一个选项,甚至不会加载)。