{"record":{"id":"9d2853897ca4edd1","repo":"OpenBB-finance/OpenBB","slug":"could-not-import-charting-modules-install-with-p-9d2853","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/port_info.py","lineNumber":17,"sourceCode":"\"\"\"Plotting functions for IMF Maritime Chokepoint Information\"\"\"\n\nfrom openbb_imf.models.port_info import ImfPortInfoData\n\n\ndef plot_port_info_map(data: list[ImfPortInfoData]):\n    \"\"\"Plot the port information on a map showing regional geography with gradient-colored markers.\"\"\"\n    # pylint: disable=import-outside-toplevel\n    from numpy import nan\n    from openbb_core.app.model.abstract.error import OpenBBError\n    from pandas import DataFrame\n\n    try:\n        import plotly.express as px\n        from openbb_charting.core.openbb_figure import OpenBBFigure\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, ImfPortInfoData) for item in data)\n    ):\n        raise OpenBBError(\"Invalid data format. Expected a list of ImfPortInfoData.\")\n    if len(data) == 0:\n        raise OpenBBError(\"No data to plot.\")\n\n    df = DataFrame([item.model_dump() for item in data]).query(\"vessel_count_total > 0\")\n\n    min_size, max_size = 4, 10\n\n    if \"country\" in df.columns and df[\"country\"].nunique() == 1:","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/views/port_info.py#L1-L35","documentation":"The IMF port-info map view lazily imports plotly.express, OpenBBFigure, and (earlier) numpy/pandas inside the function; if openbb-charting or plotly is missing/broken, it raises OpenBBError chaining the underlying import exception. Charting stays an optional dependency, so this fires only when the map view is actually used.","triggerScenarios":"Calling obb.economy.imf.port_info(chart=True) in an environment lacking openbb-charting/plotly, or where plotly.express cannot import due to a version conflict or corrupted install.","commonSituations":"Minimal installs without the charting extra; Docker/CI images trimmed of optional packages; plotly major-version upgrades breaking openbb-charting's imports; multiple venvs where the wrong interpreter runs the app.","solutions":["pip install openbb-charting.","Test the import directly: python -c \"import plotly.express; from openbb_charting.core.openbb_figure import OpenBBFigure\" and resolve whatever error it prints (usually pin a compatible plotly version).","Rebuild the environment if deps are inconsistent.","Or set chart=False and render the port data with your own plotting stack."],"exampleFix":"# before: OpenBBError: Could not import Charting modules ...\nobb.economy.imf.port_info(chart=True)\n# after\npip install openbb-charting\nobb.economy.imf.port_info(chart=True)","handlingStrategy":"validation","validationCode":"def charting_available() -> bool:\n    try:\n        import plotly.express  # noqa\n        from openbb_charting.core.openbb_figure import OpenBBFigure  # noqa\n        return True\n    except Exception:\n        return False\n\nif not charting_available():\n    obb.economy.imf.port_info(chart=False)","typeGuard":"def charting_available() -> bool:\n    try:\n        import plotly.express  # noqa\n        from openbb_charting.core.openbb_figure import OpenBBFigure  # noqa\n        return True\n    except Exception:\n        return False","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\ntry:\n    fig = plot_port_info_map(data)\nexcept OpenBBError as e:\n    if 'Could not import Charting modules' in str(e):\n        disable_charts_and_show_table(data)\n    else:\n        raise","preventionTips":["Install openbb-charting wherever charts render","CI-import plotly.express for chart features","Declare openbb-charting in deployment images, not just dev envs"],"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"}