ZhuLinsen/daily_stock_analysis · error · SystemExit
longbridge SDK is not installed. Run `pip install -r…
Error message
longbridge SDK is not installed. Run `pip install -r requirements.txt` first.
What it means
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.
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.
Example fix
# before $ python scripts/generate_longbridge_oauth_token.py --client-id xxx longbridge SDK is not installed. Run `pip install -r requirements.txt` first. # after $ python -m pip install -r requirements.txt $ python scripts/generate_longbridge_oauth_token.py --client-id xxx
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec("longbridge") is None:
raise SystemExit("Install deps first: python -m pip install -r requirements.txt") Type guard
def longbridge_available() -> bool:
return importlib.util.find_spec("longbridge.openapi") is not None Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 未安装 Futu OpenAPI SDK;请先执行 `pip install…
- 未找到状态为 ACTIVE 的 Futu REAL 普通或 MASTER 证券账户
- Cannot convert to Longbridge symbol
- generated Web index not found
- Longbridge QuoteContext not available
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/d4ff97cb774e109d.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/generate_longbridge_oauth_token.py:49
"--client-id",
default=_default_client_id(),
help="OAuth client_id. Defaults to LONGBRIDGE_OAUTH_CLIENT_ID, then LONGBRIDGE_APP_KEY.",
)
parser.add_argument(
"--verify-symbol",
default="",
help="Optional Longbridge symbol such as AAPL.US or 700.HK to verify QuoteContext after auth.",
)
args = parser.parse_args()
client_id = (args.client_id or "").strip()
if not client_id:
parser.error("missing --client-id or LONGBRIDGE_OAUTH_CLIENT_ID")
try:
from longbridge.openapi import Config, OAuthBuilder, QuoteContext
except Exception as exc:
raise SystemExit(
"longbridge SDK is not installed. Run `pip install -r requirements.txt` first."
) from exc
def show_url(url: str) -> None:
print(f"Open this URL to authorize Longbridge OAuth:\n{url}\n")
oauth = OAuthBuilder(client_id).build(show_url)
config = Config.from_oauth(oauth)
if args.verify_symbol:
ctx = QuoteContext(config)
quote = ctx.quote([args.verify_symbol])[0]
print(f"Verified {args.verify_symbol}: {getattr(quote, 'last_done', None)}")
token_cache = _token_cache_path(client_id)
print(f"OAuth token cache: {token_cache}")
print(
"For GitHub Actions, store the base64 of this file as "View on GitHub (pinned to 5159bd72e8)