OpenBB-finance/OpenBB · error · OpenBBError

Could not import Charting modules. Install with `pip install

Error message

Could not import Charting modules. Install with `pip install openbb-charting`. -> {e}

What it means

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.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/views/port_info.py:17

"""Plotting functions for IMF Maritime Chokepoint Information"""

from openbb_imf.models.port_info import ImfPortInfoData


def plot_port_info_map(data: list[ImfPortInfoData]):
    """Plot the port information on a map showing regional geography with gradient-colored markers."""
    # pylint: disable=import-outside-toplevel
    from numpy import nan
    from openbb_core.app.model.abstract.error import OpenBBError
    from pandas import DataFrame

    try:
        import plotly.express as px
        from openbb_charting.core.openbb_figure import OpenBBFigure
    except Exception as e:
        raise OpenBBError(
            "Could not import Charting modules. Install with `pip install openbb-charting`."
            + f" -> {e}"
        ) from e

    if (
        data is not None
        and not isinstance(data, list)
        or not all(isinstance(item, ImfPortInfoData) for item in data)
    ):
        raise OpenBBError("Invalid data format. Expected a list of ImfPortInfoData.")
    if len(data) == 0:
        raise OpenBBError("No data to plot.")

    df = DataFrame([item.model_dump() for item in data]).query("vessel_count_total > 0")

    min_size, max_size = 4, 10

    if "country" in df.columns and df["country"].nunique() == 1:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. pip install openbb-charting.
  2. 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).
  3. Rebuild the environment if deps are inconsistent.
  4. Or set chart=False and render the port data with your own plotting stack.

Example fix

# before: OpenBBError: Could not import Charting modules ...
obb.economy.imf.port_info(chart=True)
# after
pip install openbb-charting
obb.economy.imf.port_info(chart=True)
Defensive patterns

Strategy: validation

Validate before calling

def charting_available() -> bool:
    try:
        import plotly.express  # noqa
        from openbb_charting.core.openbb_figure import OpenBBFigure  # noqa
        return True
    except Exception:
        return False

if not charting_available():
    obb.economy.imf.port_info(chart=False)

Type guard

def charting_available() -> bool:
    try:
        import plotly.express  # noqa
        from openbb_charting.core.openbb_figure import OpenBBFigure  # noqa
        return True
    except Exception:
        return False

Try / catch

from openbb_core.app.model.abstract.error import OpenBBError
try:
    fig = plot_port_info_map(data)
except OpenBBError as e:
    if 'Could not import Charting modules' in str(e):
        disable_charts_and_show_table(data)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/9d2853897ca4edd1. Report an issue: GitHub.