gpt4 book ai didi

python - 无法在终端 : "execution_count": null 中执行 jupyter notebook

转载 作者:行者123 更新时间:2023-12-05 03:46:34 26 4
gpt4 key购买 nike

我有一个测试 jupyter notebook“Untitled.ipynb”,它只包含一个带有 print("Hello") 的单元格。作为一个文本文件,这个笔记本看起来像这样:

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Hello\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "test-kernel",
"language": "python",
"name": "test-kernel"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

我可以在 .ipynb 文件中完美地执行它,但是当我想在终端中使用 ipython Untitled.ipynb 运行它时,它会返回

(env) ...$ ipython Untitled.ipynb 
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~/.../Untitled.ipynb in <module>
3 {
4 "cell_type": "code",
----> 5 "execution_count": null,
6 "metadata": {},
7 "outputs": [],

NameError: name 'null' is not defined

根据我的谷歌搜索结果,我手动将“execution_count”更改为一个整数(例如 0、1)和 None。在这两种情况下,错误都会消失,但终端不会打印任何内容。它只是终止。奇怪的是它几天前就开始工作了……系统运行 Linux Ubuntu 18.04,virtualenv 被激活并且 pip list 通常包含运行 ipython 内核所需的一切(见下文) .

ipykernel              5.3.4
ipython 7.2.0
ipython-genutils 0.2.0
jupyter-client 6.1.7
jupyter-core 4.6.3

有没有人知道如何解决这个问题或任何提示我可以尝试什么?

最佳答案

这是我对这个错误的理解

      4    "cell_type": "code",
5 "execution_count": null,
6 "metadata": {},
7 "outputs": [],

NameError: name 'null' is not defined

我了解到这主要是因为 python 笔记本中有一个空单元格,我们正在尝试执行如下操作:

enter image description here

只需从 {} 中删除该部分的代码(用红线表示)

在Jupyternotebook中打开文件并删除单元格

或者

根据单元格的顺序添加一个数字代替空值

关于python - 无法在终端 : "execution_count": null 中执行 jupyter notebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65230573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com