命令行下运行.ipynb文件

每次运行.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
  • 9
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值