The Python Oracle

How to run an .ipynb Jupyter Notebook from terminal?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 How To Run An .Ipynb Jupyter Notebook From Terminal?
00:28 Answer 1 Score 43
00:42 Accepted Answer Score 174
00:59 Answer 3 Score 248
01:31 Answer 4 Score 71
01:41 Thank you

--

Full question
https://stackoverflow.com/questions/3554...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #jupyternotebook #ipython #nbconvert

#avk47



ANSWER 1

Score 248


nbconvert allows you to run notebooks with the --execute flag:

jupyter nbconvert --execute <notebook>

If you want to run a notebook and produce a new notebook, you can add --to notebook:

jupyter nbconvert --execute --to notebook <notebook>

Or if you want to replace the existing notebook with the new output:

jupyter nbconvert --execute --to notebook --inplace <notebook>

Since that's a really long command, you can use an alias:

alias nbx="jupyter nbconvert --execute --to notebook"
nbx [--inplace] <notebook>



ACCEPTED ANSWER

Score 174


From the command line you can convert a notebook to python with this command:

jupyter nbconvert --to python nb.ipynb

https://github.com/jupyter/nbconvert

You may have to install the python mistune package:

sudo pip install -U mistune



ANSWER 3

Score 71


In your Terminal run ipython:

ipython

then locate your script and put there:

%run your_script.ipynb



ANSWER 4

Score 43


You can export all your code from .ipynb and save it as a .py script. Then you can run the script in your terminal.

code export sample

Hope it helps.