Run Jupyter Notebook (.ipynb) from command line as if it were a .py file

随声附和 提交于 2019-12-04 12:36:56

You can send the jupyter nbconvert to stranded output and pipe that to python.

jupyter nbconvert --to script --execute --stdout test_nbconvert.ipynb | python
Robin Nemeth

A workaround is a small shell script that has three parts

  1. converting the notebook
  2. executing created script
  3. removing the script

create a file runnb.sh

#!/bin/sh
# First argument is the notebook you would like to run
notebook=$1
scriptname="$(basename $notebook .ipynb)".py

jupyter nbconvert --to script --execute ${notebook} && python ${scriptname}
rm ${scriptname}

use as such:

$ ./runnb.sh nbconvert_test.ipynb

EDIT: According to this answer, this command should do just fine jupyter nbconvert --execute test_nbconvert.ipynb (just leav out the --to flag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!