简体   繁体   中英

How to run python script daily

Every morning I produce a series of charts on python. To do so, I:

  1. Open Spyder
  2. Run my "packages" script (packages.py) which instructs python to import all the modules necessary (for example, datetime)
  3. Run my chart script (Good Morning.py) which creates the charts and prints them as in PDF in a folder. A further complication for this step is that I cannot hit "run file" in Spyder as I can do for step 2. For some reason Python does not recognize that I have imported my modules already and I get a message "NameError: name 'date' is not defined" (maybe because the.py files are in different folders). So I have to highlight the lines of code in this "Good Morning.py" file and then run the selection or current line (Fn+F9 on Mac) which does work.

Is there a way for me to automate this task and have it run daily without even having to do step 1?

First create Exe to avoid the first step and try to schedule it using windows scheduler to run it everyday.

Create Executable for code
Windows Scheduler

You need to create a environment with all the dependancies installed there, then you can run the script through CronJob. enter link description here

For unix:

Blockquote

For windows:

Cron job on windows

Virtual env:

creating virtual environment

CronJob from in virtual env:running cron through virtual env

Just do one thing.. You can use AWS and write a script to run your code daily morning(You won't be getting those import errors in AWS). Everyday you just have to open AWS and download your PDF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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