我有以下导入错误
"ImportError:没有名为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
Run Code Online (Sandbox Code Playgroud)
我已经安装了APS调度程序:sudo pip install apscheduler
我也升级了使用:sudo pip install apscheduler --upgrade还使用"sudo apt-get install update && sudo apt-get upgrade"升级了我的系统
小智 27
我有同样的问题,但后来我发现,
我安装了apscheduler版本3然后我转移到版本2.1.2使用,
pip uninstall apscheduler
pip install apscheduler==2.1.2
Run Code Online (Sandbox Code Playgroud)
在切换到版本2.1.2之前只需要结帐,如果你想使用版本3中添加的额外功能.在我的情况下,我不想要太多.
你的导入是错误的.它应该是:
from apscheduler.schedulers.blocking import BlockingScheduler
Run Code Online (Sandbox Code Playgroud)
这里的参考示例:
"""
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26130 次 |
| 最近记录: |