9

I am having following import error

"ImportError: No module named scheduler"

when I run the following python script:

"""
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

I have installed APS scheduler using: sudo pip install apscheduler

I have also upgraded using: sudo pip install apscheduler --upgrade Also upgraded my system using "sudo apt-get install update && sudo apt-get upgrade"

27

I got same issue, but then I found,

I had installed apscheduler version 3 then I shifted to version 2.1.2 using,

pip uninstall apscheduler
pip install apscheduler==2.1.2

Just checkout before switching to version 2.1.2, If you wanted to use extra features added in version 3. In my case I didn't wanted much.

| improve this answer | |
11

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
| improve this answer | |
  • 1
    the "here" url is invalid – Steve Jiang Jan 3 '19 at 7:17
  • 1
    @SteveJiang: Thanks. Fixed. – Gerrat Jan 7 '19 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.