{"record":{"id":"daa713d0385b2325","repo":"OpenBB-finance/OpenBB","slug":"could-not-import-charting-modules-install-with-p","errorCode":null,"errorMessage":"Could not import Charting modules. Install with `pip install openbb-charting`. -> {e}","messagePattern":"Could not import Charting modules\\. Install with `pip install openbb-charting`\\. -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/views/maritime_chokepoint_info.py","lineNumber":20,"sourceCode":"\nfrom openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData\n\n\ndef plot_chokepoint_annual_avg_vessels(\n    data: list[ImfMaritimeChokePointInfoData], theme=\"light\"\n):\n    \"\"\"Plot the average annual vessels for each chokepoint.\"\"\"\n    # pylint: disable=import-outside-toplevel\n    import datetime  # noqa\n    from openbb_core.app.model.abstract.error import OpenBBError\n    from pandas import DataFrame\n\n    try:\n        from openbb_charting.core.openbb_figure import OpenBBFigure\n        from plotly import graph_objects as go\n        from plotly.subplots import make_subplots\n    except Exception as e:\n        raise OpenBBError(\n            \"Could not import Charting modules. Install with `pip install openbb-charting`.\"\n            + f\" -> {e}\"\n        ) from e\n\n    if (\n        data is not None\n        and not isinstance(data, list)\n        or not all(isinstance(item, ImfMaritimeChokePointInfoData) for item in data)\n    ):\n        raise OpenBBError(\n            \"Invalid data format. Expected a list of ImfMaritimeChokePointInfoData.\"\n        )\n    if len(data) == 0:\n        raise OpenBBError(\"No data to plot.\")\n\n    df = DataFrame([item.model_dump() for item in data])\n    if theme == \"dark\":\n        geo_bgcolor = \"rgba(0,0,0,0)\"","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/views/maritime_chokepoint_info.py#L2-L38","documentation":"The IMF maritime chokepoint chart view lazily imports plotly and openbb-charting (OpenBBFigure) inside the function; if either is missing or broken, it raises OpenBBError with the underlying import exception chained. This keeps charting an optional dependency for the IMF provider.","triggerScenarios":"Calling obb.economy.imf.maritime_chokepoint(chart=True) (or the equivalent chart view) in an environment where openbb-charting or plotly is not installed, or where a conflicting plotly version breaks the import of openbb_charting.core.openbb_figure or plotly.graph_objects.","commonSituations":"Installing openbb without the charting extra; a venv where plotly was upgraded past compatibility; partial installs where openbb-charting exists but plotly is absent; CI images trimmed of optional deps.","solutions":["Install charting support: pip install openbb-charting (this brings plotly).","If already installed, verify importability: python -c \"from openbb_charting.core.openbb_figure import OpenBBFigure\" and fix the reported import error (often a plotly version pin: pip install 'plotly>=5,<6' or the version openbb-charting requires).","Recreate/repair the virtualenv if deps are inconsistent.","Alternatively call the endpoint with chart=False and build the plot yourself with whatever plotting stack is available."],"exampleFix":"# before: OpenBBError: Could not import Charting modules ...\nobb.economy.imf.maritime_chokepoint(chart=True)\n# after\npip install openbb-charting\nobb.economy.imf.maritime_chokepoint(chart=True)","handlingStrategy":"validation","validationCode":"# Verify charting is importable before enabling charts\ndef charting_available() -> bool:\n    try:\n        from openbb_charting.core.openbb_figure import OpenBBFigure  # noqa\n        import plotly.graph_objects  # noqa\n        return True\n    except Exception:\n        return False\n\nchart = charting_available()","typeGuard":"def charting_available() -> bool:\n    try:\n        from openbb_charting.core.openbb_figure import OpenBBFigure  # noqa\n        import plotly.graph_objects  # noqa\n        return True\n    except Exception:\n        return False","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\ntry:\n    fig = plot_maritime_chokepoint_info(data, theme=theme)\nexcept OpenBBError as e:\n    if 'Could not import Charting modules' in str(e):\n        pip_install_hint = 'pip install openbb-charting'\n        disable_charts()  # degrade to table-only output\n    else:\n        raise","preventionTips":["Install openbb-charting in environments that will render charts","Add a smoke-test import of openbb_charting to CI for chart-dependent features","Pin plotly to the version openbb-charting requires"],"tags":["imf","charting","optional-dependency","importerror"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}