每次运行.ipynb文件都要打开jupyter notebook就比较麻烦

解决方案

1. 安装runipy

pip3 install runipy 
runipy test.ipynb
# 获取每一个cell的输出
runipy -o test.ipynb
# 将输出保存为html文件
runipy test.ipynb --html report.html

2. 利用jupyter 自带的功能

jupyter nbconvert --to notebook --execute test.ipynb --output test.ipynb
# 跳过部分有错的cell继续执行
jupyter nbconvert --to notebook --execute mynotebook.ipynb --output mynotebook.ipynb
# cell执行超时
jupyter nbconvert --to notebook --execute --allow-errors --ExecutePreprocessor.timeout=180 mynotebook.ipynb 
# 原地运行文件
jupyter nbconvert --to notebook --execute --inplace mynotebook.ipynb

3. 利用ipython

ipython -c "%run test.ipynb"

参考

  1. https://deeplearning.lipingyang.org/2018/03/28/run-jupyter-notebook-script-from-terminal/
  2. https://stackoverflow.com/questions/35545402/how-to-run-an-ipynb-jupyter-notebook-from-terminal
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐