【问题标题】:APScheduler(Advance Python Scheduler) ImportError: No module named schedulerAPScheduler(Advance Python Scheduler) ImportError: No module named scheduler
【发布时间】:2014-09-15 06:44:21
【问题描述】:

我遇到以下导入错误

“ImportError: No module named scheduler”

当我运行以下 python 脚本时:

"""
Demonstrates how to use the blocking scheduler to schedule a job that execute$
"""

from datetime import datetime
import os

from apscheduler.scheduler 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

我已经安装了 APS 调度程序,使用: sudo pip install apscheduler

我还使用以下方式进行了升级: sudo pip install apscheduler --upgrade 还使用“sudo apt-get install update && sudo apt-get upgrade”升级了我的系统

【问题讨论】:

    标签: python


    【解决方案1】:

    我遇到了同样的问题,但后来我发现,

    我已经安装了 apscheduler 版本 3 然后我转移到版本 2.1.2 使用,

    pip uninstall apscheduler
    pip install apscheduler==2.1.2
    

    在切换到版本 2.1.2 之前只需结帐,如果您想使用版本 3 中添加的额外功能。就我而言,我并不想要太多。

    【讨论】:

      【解决方案2】:

      您的导入错误。应该是:

      from apscheduler.schedulers.blocking import BlockingScheduler
      

      参考例子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
      

      【讨论】:

      • “这里”网址无效
      • @SteveJiang:谢谢。固定。
      • 即使我退出或关闭/关闭我的电脑,它会继续运行吗?
      • @Sillians_Scilit 如果你关闭你的电脑,什么都不会运行。如果您询问如果您的计算机进入睡眠状态程序是否仍会运行,那么不会。
      • @Sillians_Scilit cmets 不适合提出新问题。尝试发布一个新问题。
      猜你喜欢
      • 2015-09-10
      • 2011-04-08
      • 2016-08-09
      • 1970-01-01
      • 2017-02-10
      • 2017-04-15
      • 2018-03-08
      • 2016-12-23
      • 2016-12-19
      相关资源
      最近更新 更多