ModuleNotFoundError: No module named 'apscheduler' even through installed the apscheduler package

50 views Asked by At

When I tried to start the application using this command:

root@visa-service-5fcc84fc6f-hfhxn:~/visa# python3.10 main_api.py
Traceback (most recent call last):
  File "/root/visa/main_api.py", line 3, in <module>
    from task.refresh_token import RefreshToken
  File "/root/visa/task/refresh_token.py", line 3, in <module>
    from apscheduler.schedulers.background import BackgroundScheduler
ModuleNotFoundError: No module named 'apscheduler'

I have already tried to install the apscheduler like this:

pdm add APScheduler
pdm add apscheduler

still did not fixed this issue. what should I do to fixed this issue? This is the main_api.py python code look like:

from dotenv import load_dotenv

from task.refresh_token import RefreshToken

if __name__ == '__main__':
    load_dotenv(verbose=True)
    refresh_token = RefreshToken()
    refresh_token.start_scheduler()

this is how I import the apschedule:

import time
from typing import List
from apscheduler.schedulers.background import BackgroundScheduler
from config.mysql_utils import VisaDB
from request import requst_api_cffi
from static.visa_sys import visa_logger
from utils.constant import Constant
import utils.account_utils as au


class RefreshToken:

    @staticmethod
    def do_access_token_refresh():
        constant = Constant()
        vb = VisaDB()
        accounts = vb.get_new_cf_user()
        account_session_query = au.AccountSessionsMysqlCffi(accounts, constant.request_data)
        if account_session_query.session_list.__len__() == 0:
            return
        visa_logger.debug("user have cloudflare captcha key")
        sessions: List[requst_api_cffi.RequestApi] = account_session_query.session_list.copy()
        session = sessions.pop()
        session.login_with_captcha(cf_key=session.cf_captcha_key)

    def start_scheduler(self):
        scheduler = BackgroundScheduler()
        rt = RefreshToken()
        scheduler.add_job(rt.do_access_token_refresh, 'cron', args=[], second='*/5', max_instances=1)
        scheduler.start()
        try:
            while True:
                time.sleep(20)
        except (KeyboardInterrupt, SystemExit):
            scheduler.shutdown()

this is the project dependencies look like:

[project]
name = ""
version = ""
description = ""
authors = [
    {name = "JiangXiaoqiang", email = "[email protected]"},
]
dependencies = [
    "aiohttp==3.8.4",
    "aiosignal==1.3.1",
    "anyio==3.6.2",
    "async-timeout==4.0.2",
    "asynctest==0.13.0",
    "attrs==23.1.0",
    "bcrypt==4.0.1",
    "Brotli==1.0.9",
    "brotlipy>=0.7.0",
    "cached-property==1.5.2",
    "charset-normalizer==3.3.2",
    "cryptography==40.0.2",
    "DBUtils==3.0.3",
    "et-xmlfile==1.1.0",
    "fabric==3.0.1",
    "fake==0.8",
    "fake-useragent>=1.3.0",
    "frozenlist==1.3.3",
    "h11==0.14.0",
    "haralyzer==2.2.0",
    "hpack==4.0.0",
    "httpcore==0.17.1",
    "httpx==0.24.0",
    "importlib-metadata==4.13.0",
    "importlib-resources==5.12.0",
    "invoke==2.1.2",
    "jwt==1.3.1",
    "multidict==6.0.4",
    "openpyxl==3.1.2",
    "paramiko==3.1.0",
    "pycurl==7.45.2",
    "PyMySQL==1.0.3",
    "PyNaCl==1.5.0",
    "pyparsing==3.0.9",
    "redis==4.5.5",
    "requests==2.31.0",
    "requests-toolbelt==1.0.0",
    "sniffio==1.3.0",
    "tls-client==0.2.1",
    "typing-extensions==4.5.0",
    "urllib3>=2.1.0",
    "yarl==1.9.2",
    "zipp>=3.17.0",
    "rsa==4.8",
    "pyopenssl>=23.2.0",
    "brotli==1.0.9",
    "xlrd==2.0.1",
    "pycryptodome>=3.19.0",
    "PyExecJS==1.5.1",
    "curl-cffi>=0.5.9",
    "smsactivate==1.5",
    "Faker==19.13.0",
    "beautifulsoup4==4.12.2",
    "soupsieve==2.5",
    "numpy==1.26.1",
    "rdpywheel>=0.1.28",
    "python-dotenv==1.0.0",
    "pyjwt==2.8.0",
    "selenium==4.15.2",
    "webdriver-manager>=4.0.1",
    "chromedriver-autoinstaller>=0.6.2",
    "apscheduler>=3.10.4",
    "rd-undetected-chromedriver>=3.5.6",
    "ndg-httpsclient>=0.5.1",
    "pyasn1>=0.5.0",
    "seleniumbase>=4.21.4",
]
requires-python = ">=3.10,<3.13"
readme = "README.md"
license = {text = "MIT"}

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
1

There are 1 answers

0
Dolphin On

Try to run the application like this will fixed this issue:

pdm run python3.10 /root/visa/main_api.py > /root/visa/starup.log 

more info from the official discussion: https://github.com/pdm-project/pdm/discussions/2414