Can I run Jupyter notebook cells in commandline?

pylang picture pylang · Feb 18, 2016 · Viewed 39.1k times · Source

I am deploying a Python package, and I would like to run a simple test to see if all cells in my notebook will run without errors. I would like to test this via commandline as I have issues running a notebook in virtualenv. Is there are simple command-line way to test this?


Note to the moderator: this question has been marked as a duplicate of How to run an .ipynb Jupyter Notebook from terminal? . However, this question was posted (asked Feb 18 '16 at 2:49) several days before that one (asked Feb 22 '16 at 3:35). At most, that post might be marked as a duplicate, and if deemed so, an appropriate action would be to merge the two questions, maintaining this, the original, as the master.

However, these questions may not be duplicates (the intent of the other author is unclear). Regardless, this question and it's answers specifically address executing cells within a jupyter notebook from the terminal, not simply converting notebooks to python files.

Answer

geekazoid picture geekazoid · Oct 28, 2016

nbconvert (a jupyter tool for notebook conversion) allows you to do this without any extra packages:

Just go to your terminal and type

$ jupyter nbconvert --to notebook --inplace --execute mynotebook.ipynb

Source

(Thanks Stephan for suggesting the --inplace flag)