简体   繁体   English

通过命令行运行 jupyter notebook 并将输出记录到文件中

[英]Run jupyter notebook through command line and log outputs to a file

I am running a notebook on command line in AWS SageMaker but I am not able to log outputs to a file.我在 AWS SageMaker 的命令行上运行笔记本,但无法将输出记录到文件中。 I added print , logging.info and sys.stdout.write statements in hope of capturing something but to no avail.我添加了printlogging.infosys.stdout.write语句,希望能捕捉到一些东西,但无济于事。

Below is the code I am using下面是我正在使用的代码

NOTEBOOK_FILE="/home/ec2-user/SageMaker/mynb.ipynb"
LOG_FILE="/home/ec2-user/SageMaker/logs.txt"

nohup jupyter nbconvert  --to notebook --inplace --ExecutePreprocessor.timeout=-1 --ExecutePreprocessor.kernel_name=python3 --execute "$NOTEBOOK_FILE" > "$LOG_FILE" &

On doing cat "$LOG_FILE" I get just a couple lines of logs and nothing after that.在执行cat "$LOG_FILE"时,我只得到几行日志,之后什么也没有。 Output is below -输出低于 -

[NbConvertApp] WARNING | Config option `kernel_spec_manager_class` not recognized by `NbConvertApp`.
[NbConvertApp] Converting notebook /home/ec2-user/SageMaker/tata1mg.ipynb to notebook
[NbConvertApp] Executing notebook with kernel: python3

PS: PS:

You can convert the notebook to a script: jupyter nbconvert --to script "$NOTEBOOK_FILE"您可以将笔记本转换为脚本: jupyter nbconvert --to script "$NOTEBOOK_FILE"

and then run the Python Script: python3 mynb.py > $LOG_FILE然后运行 ​​Python 脚本: python3 mynb.py > $LOG_FILE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM