how to run a python jupyter notebook daily automatically

后端 未结 7 895
无人共我
无人共我 2020-12-14 08:35

I have a code in a python jupyter notebook but i need to run this every day so I would like to know if there\'s a way to set this, I really appreciate it

7条回答
  •  天涯浪人
    2020-12-14 08:57

    Update
    recently I came across papermill which is for executing and parameterizing notebooks.

    https://github.com/nteract/papermill

    papermill local/input.ipynb s3://bkt/output.ipynb -p alpha 0.6 -p l1_ratio 0.1
    

    This seems better than nbconvert, because you can use parameters. You still have to trigger this command with a scheduler. Below is an example with cron on Ubuntu.


    Old Answer

    nbconvert --execute
    

    can execute a jupyter notebook, this embedded into a cronjob will do what you want.

    Example setup on Ubuntu:

    Create yourscript.sh with the following content:

    /opt/anaconda/envs/yourenv/bin/jupyter nbconvert \
                          --execute \
                          --to notebook /path/to/yournotebook.ipynb \
                          --output /path/to/yournotebook-output.ipynb
    

    You have more options except --to notebook. I like this option since you have a fully executable "log"-File afterwards.

    I recommend using a virtual environment to run your notebook, to avoid that future updates mess with your script. Do not forget to install nbconvert into the environment.

    Now create a cronjob, that runs every day e.g. at 5:10 AM, by typing crontab -e in your terminal and add this line:

    10 5 * * * /path/to/yourscript.sh
    

提交回复
热议问题