{"record":{"id":"d4ff97cb774e109d","repo":"ZhuLinsen/daily_stock_analysis","slug":"longbridge-sdk-is-not-installed-run-pip-install","errorCode":null,"errorMessage":"longbridge SDK is not installed. Run `pip install -r requirements.txt` first.","messagePattern":"longbridge SDK is not installed\\. Run `pip install -r requirements\\.txt` first\\.","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"scripts/generate_longbridge_oauth_token.py","lineNumber":49,"sourceCode":"        \"--client-id\",\n        default=_default_client_id(),\n        help=\"OAuth client_id. Defaults to LONGBRIDGE_OAUTH_CLIENT_ID, then LONGBRIDGE_APP_KEY.\",\n    )\n    parser.add_argument(\n        \"--verify-symbol\",\n        default=\"\",\n        help=\"Optional Longbridge symbol such as AAPL.US or 700.HK to verify QuoteContext after auth.\",\n    )\n    args = parser.parse_args()\n\n    client_id = (args.client_id or \"\").strip()\n    if not client_id:\n        parser.error(\"missing --client-id or LONGBRIDGE_OAUTH_CLIENT_ID\")\n\n    try:\n        from longbridge.openapi import Config, OAuthBuilder, QuoteContext\n    except Exception as exc:\n        raise SystemExit(\n            \"longbridge SDK is not installed. Run `pip install -r requirements.txt` first.\"\n        ) from exc\n\n    def show_url(url: str) -> None:\n        print(f\"Open this URL to authorize Longbridge OAuth:\\n{url}\\n\")\n\n    oauth = OAuthBuilder(client_id).build(show_url)\n    config = Config.from_oauth(oauth)\n\n    if args.verify_symbol:\n        ctx = QuoteContext(config)\n        quote = ctx.quote([args.verify_symbol])[0]\n        print(f\"Verified {args.verify_symbol}: {getattr(quote, 'last_done', None)}\")\n\n    token_cache = _token_cache_path(client_id)\n    print(f\"OAuth token cache: {token_cache}\")\n    print(\n        \"For GitHub Actions, store the base64 of this file as \"","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/scripts/generate_longbridge_oauth_token.py#L31-L67","documentation":"scripts/generate_longbridge_oauth_token.py wraps the import of longbridge.openapi in try/except and exits with this message when the SDK is absent or broken. It is an environment guard: the OAuth flow cannot even begin without the SDK, and the message directs you to install repo requirements. Note SystemExit(str) prints the message and exits with code 1.","triggerScenarios":"Running the script in a venv where requirements.txt was never installed, or where the longbridge wheel failed to install (platform mismatch); importing longbridge.openapi raising for a corrupted install; running under a different interpreter than the one you installed packages into.","commonSituations":"Fresh clone, script run before pip install -r requirements.txt; multiple Python environments (system vs venv) and the script picking the wrong one; longbridge SDK removed or renamed in a newer requirements snapshot.","solutions":["Install deps into the active interpreter: pip install -r requirements.txt (or at minimum pip install longbridge).","Verify the interpreter matches: which python / python -m pip install -r requirements.txt so packages and script share the venv.","Test the import directly: python -c \"import longbridge.openapi\" — if that fails with an ImportError detailing the module, reinstall just that package.","If the wheel is unavailable for your platform, check requirements.txt pins or the longbridge docs for supported Python versions."],"exampleFix":"# before\n$ python scripts/generate_longbridge_oauth_token.py --client-id xxx\nlongbridge SDK is not installed. Run `pip install -r requirements.txt` first.\n\n# after\n$ python -m pip install -r requirements.txt\n$ python scripts/generate_longbridge_oauth_token.py --client-id xxx","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"longbridge\") is None:\n    raise SystemExit(\"Install deps first: python -m pip install -r requirements.txt\")","typeGuard":"def longbridge_available() -> bool:\n    return importlib.util.find_spec(\"longbridge.openapi\") is not None","tryCatchPattern":null,"preventionTips":["Run pip install -r requirements.txt in the active venv before running repo scripts.","Use python -m pip so packages install into the interpreter that runs the script.","Gate SDK-dependent scripts on an import check with a clear message."],"tags":["longbridge","dependency","setup","script"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}