Run Jupyter Notebook Script From Terminal - Deep Learning Garden

Skip to content

Normally people run jupyter notebook via browser, but in some situation, we will need to run it from terminal, for example, when running the script takes long time.

This post introduces how to run a jupyter notebook script from terminal.

Solution  I:

runipy can do this. runipy will run all cells in a notebook. If an error occurs, the process will stop.

  • Install  runipy package
$ pip3 install runipy # for python 3.x $ pip install runipy # for python 2.x
  • runipy command-line usages
  • To run a .ipynb file as a script, run:
$ runipy MyNotebook.ipynb
  • To save the output of each cell back to the notebook file, run:
$ runipy -o MyNotebook.ipynb
  • To save the notebook output as a new notebook, run:
$ runipy MyNotebook.ipynb OutputNotebook.ipynb
  • To run a .ipynb file and generate an HTML report, run:
$ runipy MyNotebook.ipynb --html report.html

Solution  II:

The latest versions of jupyter comes with  the nbconvert command tool for notebook conversion allows us  to do this without any extra packages.

Just go to your terminal and type:

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

This will open the notebook, execute it, capture new output, and save the result in mynotebook.nbconvert.ipynb. By default, nbconvert will abort conversion if any exceptions occur during execution of a cell. If you specify --allow-errors (in addition to the --execute flag) then conversion will continue and the output from any exception will be included in the cell output.

if you meet this error,

raise exception(“Cell execution timed out”)

$ jupyter nbconvert --to notebook --execute --allow-errors --ExecutePreprocessor.timeout=180 mynotebook.ipynb 

You can use the –inplace flag as well:

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

check here for more (updated) usages about nbconvert jupyter command tool.

References:

https://pypi.python.org/pypi/runipy

http://nbconvert.readthedocs.io/en/latest/usage.html#convert-notebook 

Can I run Jupyter notebook cells in commandline?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Post navigation

Previous post: [Paper published] Check out our new machine/deep learning paper Next post: Checking from command line if Jupyter server is running and kill if needed Search for: Search

Recent Posts

  • DIRA workshop at CVPR 2020 will take place on June 14!
  • [CFP] Call for papers: CVPR 2020 DIRA Workshop
  • [Job opening] PhD and Master positions in GIScience and GeoAI
  • [Job opening] Summer interns in computer vision and machine learning!
  • [Paper published] Novel representation and method for effective zigzag noise denoising

Archives

  • June 2020
  • January 2020
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • March 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • July 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • October 2017
  • September 2017
  • August 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016

Categories

  • Active learning
  • Azure cloud computing
  • Bash shell scripting
  • C/C++
  • Computer vision
  • Conda
  • Data Mining_algorithms
  • Datasets
  • Deep learning
  • Deep Learning and Machine Learning_Great talks
  • Deep Learning_big picture
  • Deep Learning_CNN
  • Deep Learning_RNN
  • Deep Learning_TechNews
  • Deep Learning_text_nlp
  • Django
  • gensim
  • GPU
  • HPC
  • Java
  • JavaScript
  • jobs
  • Jupyter
  • Keras
  • Linux
  • Linux command
  • Machine Learning vs Deep Learning
  • Machine Learning_algorithms
  • Machine Learning_terms
  • Machine Learning_tricks4better performance
  • MPI
  • Node
  • OpenCV
  • OpenMP
  • Pandas
  • PostgreSQL
  • pySpark
  • Python
  • Python_Advanced
  • Python_Basics
  • Python_Matplotlib
  • Quotes_AI_DeepLearning_MachineLearning
  • R
  • Solr
  • Spark
  • TensorFlow
  • Ubuntu
  • Uncategorized
  • Web application dev
  • Web servers

Visual Visitor Analytics

Category Cloud

Data structures and Algorithms D3 CSS Apache Web Server Active learning C/C++ Bayesian Network Caffe Bitbucket Alan Conda Datasets Data Mining_algorithms Computer vision Bash shell scripting Big data BLM Books and Courses and Tutorials_Python Azure cloud computing Apache

Tag cloud

conda compile c/c++ algorithm Bash shell scripting active learning CNN CentOS dataset CUDA Apache web server CSV conference deep learning anaconda computer vision AI D3 Acknowledgments data Back to TOP

Tag » How To Run Ipynb File