我有以下导入错误
“导入错误:没有名为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
我已使用:sudo pip install apscheduler安装了APS调度器
我也升级了使用: sudo pip安装应用调度器-升级也升级了我的系统使用"sudo apt-get安装更新
我也有同样的问题但后来我发现,
我已经安装了apscheduler版本3,然后切换到版本2.1。2使用,
pip uninstall apscheduler
pip install apscheduler==2.1.2
在切换到2.1版之前只需签出即可。2,如果您想使用版本3中添加的额外功能。就我而言,我并不想要太多。
你的导入是错误的。它应该是:
from apscheduler.schedulers.blocking import BlockingScheduler
此处的参考示例:
"""
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