ModuleNotFoundError: No module named 'apscheduler'

9.3k Views Asked by At

it might be a silly problem.

I have no idea about why I am facing ModuleNotFoundError: No module named 'apscheduler' but I have already successfully installed APscheduler.

I have tried uninstalling it and re-install the specific version of APscheduler, but it didn't work. I also tried installing it on virtualenv, but it didn't work as well.

Python: | pip: 20.3.3 | version: 3.7.3 OS: Linux (Ubuntu 20.04)

from __future__ import absolute_import
import octoprint.plugin
from apscheduler.schedulers.background import BackgroundScheduler

from influxdb_client import InfluxDBClient, Point
import requests

def __init__(self):
    super().__init__()
    self.backgroundScheduler = BackgroundScheduler()

logging as follows:

Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/plugin/core.py", line 1298, in _import_plugin
    module = _load_module(module_name, spec)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/plugin/core.py", line 69, in _load_module
    return imp.load_module(name, f, filename, details)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 238, in load_module
    return load_package(name, filename)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 212, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_CMfgDataAcquisition/__init__.py", line 13, in <module>
    from apscheduler.schedulers.background import BackgroundScheduler
ModuleNotFoundError: No module named 'apscheduler'

enter image description here

APscheduler == 3.6.3 has been installed.

3

There are 3 best solutions below

0
On

Don't use sudo when installing modules with pip. If you have already setup a virtualenv, activate it and then install your dependencies without sudo

source {YOUR_VENV}/bin/activate    
pip install APscheduler==3.6.3

If you see your traceback, you're using packages from /home/pi/oprint/lib/python3.7/site-packages/ whereas you're installing your dependencies on /usr/lib/python3/dist-packages/

Otherwise, verify your $PATH and $PYTHONPATH

0
On

This was also posted to APScheduler's bug tracker (as a feature request no less), and it contained critical information not given here on SO: the output of sudo pip install APScheduler==3.6.3: enter image description here

As you can see from the path (/usr/local/lib/python3.8/dist-packages), OP was installing it on Python 3.8 and then trying to import it from Python 3.7.

The solution is to use Python 3.7 to install it: python3.7 -m pip install APScheduler==3.6.3. Note, however, that 3.6.3 is not the latest release.

1
On

Solved Same problem here. Installing with pip3 didn't work. I downloaded APScheduler from PyPi and installed it directly, same problem.

I got a hunch, I restarted my laptop, and it worked! I don't know why, I never have problems installing modules, but it works after restart... Give it a try!