menu

Questions & Answers

Can't execute jupyter notebook in terminal: "execution_count": null

I have a test jupyter notebook "Untitled.ipynb" which just consists of one cell with print("Hello"). As a text file this notebook looks like this:

{
 "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
}

I can perfectly execute it in the .ipynb file, but when I want to run it in the terminal with ipython Untitled.ipynb it returns

(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

Based on my google results I manually changed "execution_count" to an integer (e.g. 0, 1) and None. In both cases the error disappears but the terminal doesn't print anything. It just terminates. The weird thing is that it worked a few days ago...The system runs with Linux Ubuntu 18.04, the virtualenv is activated and pip list contains normally everything you need to run an ipython kernel (see below).

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

Does anyone have any idea how to solve this or any hints what I could try?

Answers(4) :
python3 -m pip install nbclient

jupyter execute notebook.ipynb
Comments:
2023-01-24 23:52:15
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.

You have to do just one thing : Remove all empty cells from jupyter notebook

Comments:
2023-01-24 23:52:15
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Here is something I understood about this error

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

NameError: name 'null' is not defined

What I learned that this is mainly because there is an empty cell in the python notebook that we are trying to execute something like this:

enter image description here

Just remove the code from {}(stricken by the red line) for that part

OR

open the file in the Jupyternotebook and delete the cell

Or

Add a number in in place of null based on the sequence of the cell

Python cannot use null.
Try using None instead of null.
why do you have to use null?

Comments:
2023-01-24 23:52:15
As I stated "Based on my google results I manually changed "execution_count" to an integer (e.g. 0, 1) and None. In both cases the error disappears but the terminal doesn't print anything. It just terminates.". In addition I'm not the one who puts null there. It is the system behind jupyter that does that.
2023-01-24 23:52:15
I'm sorry if I offended you. I didn't understand the purpose of your question, so I gave you the above answer.
2023-01-24 23:52:15
You did not offend me :D But I already tried out this solution. This helps to remove the error, but the notebook just terminates and doesn't print anything. So still it's not working.