nbconvert Execute Jupyter notebook from Command Line output results

二次信任 提交于 2020-01-13 16:02:55

问题


This question must've been asked before, but I couldn't find a right answer. I would like to run the Jupyter notebook from command line and save the result to certain files.

I got this running,

jupyter nbconvert --to python --execute mynotebook.ipynb >> mylog.out.log 2>&1

This command executes mynotebook.ipynb properly, but in the log file, it only contains 3 lines if the execution is successful.

[NbConvertApp] Converting notebook mynotebook.ipynb to python
[NbConvertApp] Executing notebook with kernel: python2
[NbConvertApp] Writing 1931 bytes to mynotebook.ipynb.py

If the notebook raises some exception, it will show the exception in the log file too. But where do I see the results of the notebook?

For example, in my notebook, I have

print 'hello world'

This output doesn't show in my command line interface or in the log file. Is there an approach or a parameter setting to keep the output into a log file? I would like to see the detailed results of mynotebook.ipynb.

Any thought? or any other better method than jupyter nbconvert?


Also, it that possiable to include the datetime into the log file? it would be very helpful to have the time included.


回答1:


You can try --stdout and you have to convert to something like html to see output for example

jupyter nbconvert --to html mynotebook.ipynb --stdout --ExecutePreprocessor.kernel_name=python --ExecutePreprocessor.enabled=True


来源:https://stackoverflow.com/questions/40183299/nbconvert-execute-jupyter-notebook-from-command-line-output-results

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