{"record":{"id":"5a00efea19151e4d","repo":"ZhuLinsen/daily_stock_analysis","slug":"schedule-pip-install-schedule","errorCode":null,"errorMessage":"请安装 schedule 库: pip install schedule","messagePattern":"请安装 schedule 库: pip install schedule","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/scheduler.py","lineNumber":111,"sourceCode":"        self,\n        schedule_time: str = \"18:00\",\n        schedule_time_provider: Optional[Callable[[], str]] = None,\n        schedule_times: Optional[Sequence[str]] = None,\n        schedule_times_provider: Optional[Callable[[], Union[Sequence[str], str]]] = None,\n        register_signals: bool = True,\n    ):\n        \"\"\"\n        初始化调度器\n\n        Args:\n            schedule_time: 每日执行时间，格式 \"HH:MM\"\n        \"\"\"\n        try:\n            import schedule\n            self.schedule = schedule\n        except ImportError:\n            logger.error(\"schedule 库未安装，请执行: pip install schedule\")\n            raise ImportError(\"请安装 schedule 库: pip install schedule\")\n\n        self.schedule_time = schedule_time\n        self.schedule_times = (\n            normalize_schedule_times(schedule_times, fallback_time=schedule_time)\n            if schedule_times is not None\n            else [(schedule_time or \"\").strip()]\n        )\n        self._schedule_time_provider = schedule_time_provider\n        self._schedule_times_provider = schedule_times_provider\n        self.shutdown_handler = GracefulShutdown(register_signals=register_signals)\n        self._task_callback: Optional[Callable] = None\n        self._daily_job: Optional[Any] = None\n        self._daily_jobs: List[Any] = []\n        self._background_tasks: List[Dict[str, Any]] = []\n        self._running = False\n\n    def set_daily_task(self, task: Callable, run_immediately: bool = True):\n        \"\"\"","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/scheduler.py#L93-L129","documentation":"ImportError raised in StockScheduler.__init__ when the third-party 'schedule' package cannot be imported. The stdlib has no scheduler of this shape, so the dependency is required; the code logs the remediation hint and re-raises as an explicit ImportError with the pip command. It fails at scheduler construction, before any scheduling happens.","triggerScenarios":"Instantiating the scheduler in an environment where 'schedule' is not installed — a fresh venv, a Docker image built from a partial requirements install, or a deployment where requirements.txt was trimmed.","commonSituations":"Running --schedule mode without installing dev/optional deps; CI cache or slim image missing the package; dependency resolver dropped it after a version conflict; running from source without pip install -r requirements.txt.","solutions":["Install the package: pip install schedule (or pip install -r requirements.txt which pins it)","Add 'schedule' to the deployed image's requirements and rebuild","If you hit a resolver conflict, align versions so 'schedule' installs cleanly alongside the pinned stack","If you never use --schedule mode, avoid constructing StockScheduler rather than removing the dependency ad hoc"],"exampleFix":"# before\n$ python main.py --schedule\nImportError: 请安装 schedule 库\n\n# after\n$ pip install schedule\n$ python main.py --schedule","handlingStrategy":"validation","validationCode":"import importlib.util\n\ndef schedule_available() -> bool:\n    return importlib.util.find_spec(\"schedule\") is not None","typeGuard":null,"tryCatchPattern":"try:\n    scheduler = StockScheduler(schedule_time=\"09:30\")\nexcept ImportError:\n    log.error(\"Schedule mode requires 'schedule'; install deps or drop --schedule\")\n    raise SystemExit(2)","preventionTips":["Check importlib.util.find_spec('schedule') before enabling --schedule mode","Keep requirements.txt authoritative for runtime deps and install it fully in images","Fail fast at startup rather than at scheduler construction mid-run"],"tags":["dependency","scheduler","environment","import"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}