{"record":{"id":"f42c4235c71467f8","repo":"HKUDS/Vibe-Trading","slug":"tushare-not-installed-exc","errorCode":null,"errorMessage":"tushare not installed: {exc}","messagePattern":"tushare not installed: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/alpha_bench_tool.py","lineNumber":325,"sourceCode":"\n\ndef _load_csi300_panel(start: str, end: str) -> dict[str, pd.DataFrame]:\n    \"\"\"CSI 300 panel via Tushare. Includes ``amount`` (required by gtja191).\n\n    Constituents are taken from the most recent ``index_weight`` snapshot in\n    the requested window; if that call fails we degrade to a 30-name\n    blue-chip fallback so the bench still runs.\n    \"\"\"\n    token = get_env_config().data.tushare_token.strip()\n    if not token or token == \"your-tushare-token\":\n        raise RuntimeError(\n            \"TUSHARE_TOKEN not in agent/.env or environment; required for csi300 universe\"\n        )\n\n    try:\n        import tushare as ts\n    except ImportError as exc:\n        raise RuntimeError(f\"tushare not installed: {exc}\") from exc\n\n    pro = ts.pro_api(token)\n    sd = start.replace(\"-\", \"\")\n    ed = end.replace(\"-\", \"\")\n\n    codes: list[str] = []\n    constituent_source = \"tushare index_weight\"\n    constituent_source_date: str | None = None\n    membership: pd.DataFrame | None = None\n    try:\n        # Reach back before ``start`` so the snapshot that was in force on the\n        # first requested day is included; Tushare publishes month-end rosters.\n        lookback = (pd.Timestamp(start) - pd.Timedelta(days=60)).strftime(\"%Y%m%d\")\n        weights = pro.index_weight(\n            index_code=\"399300.SZ\", start_date=lookback, end_date=ed\n        )\n        if weights is not None and not weights.empty:\n            frame = weights.copy()","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/alpha_bench_tool.py#L307-L343","documentation":"The csi300 loader imports tushare lazily; if the package is not installed in the active environment, this RuntimeError wraps the ImportError with the underlying message.","triggerScenarios":"Calling the csi300 universe path in an environment where 'import tushare' fails (package not installed or wrong virtualenv/interpreter).","commonSituations":"Running the agent in a venv created from a partial requirements file; deploying with a slimmed dependency set that omitted tushare; multiple interpreters where the tool runs under a different one.","solutions":["pip install tushare into the environment running the agent","Verify with: python -c 'import tushare' using the same interpreter","Pin the dependency in requirements/pyproject if csi300 support is needed"],"exampleFix":"# before: ImportError wrapped as RuntimeError\n# after\npip install tushare","handlingStrategy":"fallback","validationCode":"try:\n    import tushare  # noqa\n    ok = True\nexcept ImportError:\n    ok = False","typeGuard":null,"tryCatchPattern":"try:\n    _load_csi300_panel(s, e)\nexcept RuntimeError as e:\n    if 'tushare not installed' in str(e):\n        subprocess.run([sys.executable, '-m', 'pip', 'install', 'tushare'], check=True)","preventionTips":["Include tushare in the deployment requirements when csi300 is enabled","Run dependency checks as a preflight step"],"tags":["dependency","import","tushare","environment"],"backgroundTag":"missing-optional-dependency","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}