jupyter notebook无法看到代码块之间的代码。

huangapple go评论81阅读模式
英文:

jupyter notebook does not see the code between blocks

问题

我是新手Jupyter Notebook,并最近遇到了奇怪的问题。在重新加载笔记本后,通常情况下我决定进入服务器并开始编辑我的项目。但是在尝试运行单个代码块后,它显示:“'variable'未定义”,尽管在先前的代码块中有它。让我通过示例来演示我的问题。

jupyter notebook无法看到代码块之间的代码。

如您所见,它显示:“'movies'未定义”,然而此变量存在于上面的代码块中,'dataset'也是如此。

是什么原因导致了这样的问题,以及如何修复它?

英文:

I'm new to Jupyter Notebook and stumbled upon weird issue recently. After reloading my notebook, as usually I decided to enter the server and start editing my project. But after trying to run an individual block of code, it shows: "'variable' is not defined", regardless of having it in the previous block. Let me show you an example to demonstrate my problem.

jupyter notebook无法看到代码块之间的代码。

as you can see is shows: 'movies' is not defined, however this variable exists in the upper block of code, same thing with 'dataset'.

What can cause such an issue and how to fix it?

答案1

得分: 1

代码始终按行运行,即使在jupyter笔记本中也是如此。如果你查看自己的图像,那么你会看到你需要修复读取数据集的问题。这可能是因为您没有初始化变量数据集并直接使用它。我认为这将解决这个问题。

英文:

The code always runs line by line, even in jupyter notebook. If you look into your own image, then you can see that you need to fix the issue with reading the dataset. It might happen because you haven't initialized the variable dataset and used it directly. In my opinion, it will fix the issue.

答案2

得分: 0

"有人曾经说过:"内核负责执行代码和管理系统资源。当内核重新启动时,它基本上会从头开始,丢弃与以前会话相关的任何先前状态或内存。这包括在该会话中定义的任何标签或变量。"

"简而言之,每次重新启动内核时,您必须重新运行每个块,因为以前的变量都会丢失。"

英文:

Once someone said : "Kernels are responsible for executing code and managing system resources. When a kernel is restarted, it essentially starts fresh, discarding any previous state or memory associated with the previous session. This includes any labels or variables that were defined within that session."
<br><br>
Simply put every time you restart your kernel you have to run every block again as previous variables are lost.

huangapple
  • 本文由 发表于 2023年6月16日 03:09:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76484817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定