APScheduler(Advance Python Scheduler) ImportError: No module named scheduler

前端 未结 2 1999
误落风尘
误落风尘 2021-02-03 12:23

I am having following import error

\"ImportError: No module named scheduler\"

when I run the following python script:

\"\"\"
Demonstrates how to         


        
2条回答
  •  独厮守ぢ
    2021-02-03 12:59

    Your import is wrong. It should be:

    from apscheduler.schedulers.blocking import BlockingScheduler
    

    Reference example here:

    """
    Demonstrates how to use the blocking scheduler to schedule a job that executes on 3 second
    intervals.
    """
    
    from datetime import datetime
    import os
    
    from apscheduler.schedulers.blocking import BlockingScheduler
    
    
    def tick():
        print('Tick! The time is: %s' % datetime.now())
    
    
    if __name__ == '__main__':
        scheduler = BlockingScheduler()
        scheduler.add_job(tick, 'interval', seconds=3)
        print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
    
        try:
            scheduler.start()
        except (KeyboardInterrupt, SystemExit):
            pass
    

提交回复
热议问题