OpenBB-finance/OpenBB · error · RuntimeError

Unable to import the required module.

Error message

Unable to import the required module.

What it means

The chokepoint chart lazily imports openbb_imf.views.maritime_chokepoint_info.plot_chokepoint_annual_avg_vessels; any exception during that import (missing openbb-imf package, moved/renamed module after a refactor) is wrapped as RuntimeError('Unable to import the required module.') with the cause chained. It is an environment/packaging error, not a data error.

Source

Thrown at openbb_platform/extensions/economy/openbb_economy/economy_views.py:537

    def economy_shipping_chokepoint_info(
        **kwargs,
    ) -> tuple["OpenBBFigure", dict[str, Any]]:
        """Maritime Chokepoint Info Chart."""
        # pylint: disable=import-outside-toplevel

        provider = kwargs.get("provider")

        if provider != "imf":
            raise RuntimeError(
                f"This charting method does not support {provider}. Supported providers: imf."
            )

        try:
            from openbb_imf.views.maritime_chokepoint_info import (
                plot_chokepoint_annual_avg_vessels,
            )
        except Exception as e:
            raise RuntimeError("Unable to import the required module.") from e

        theme = (
            kwargs.get("extra_params", {}).get("theme")
            or kwargs.get("theme")
            or getattr(kwargs["charting_settings"], "chart_style", "dark")
        )
        data = (
            kwargs.pop("data", None)
            if "data" in kwargs and kwargs["data"] is not None
            else kwargs.get("obbject_item")
        )
        fig = plot_chokepoint_annual_avg_vessels(data, theme=theme)  # type: ignore
        fig.update_layout(
            margin=dict(l=25, r=25, t=50, b=0),
        )
        content = fig.to_plotly_json()

        content["config"] = dict(responsive=False)

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Install the provider package: pip install openbb-imf.
  2. Align versions: reinstall the openbb platform bundle (pip install -U openbb) so openbb-economy and openbb-imf match.
  3. Inspect the chained exception (except RuntimeError as e: print(e.__cause__)) to confirm whether it is ModuleNotFoundError vs AttributeError on the function name.

Example fix

# before
# openbb-imf missing
fig, content = views.economy_shipping_chokepoint_info(**kwargs)  # RuntimeError

# after
# pip install openbb-imf
fig, content = views.economy_shipping_chokepoint_info(**kwargs)
Defensive patterns

Strategy: try-catch

Validate before calling

try:
    from openbb_imf.views.maritime_chokepoint_info import plot_chokepoint_annual_avg_vessels  # noqa
    imf_views_ok = True
except Exception:
    imf_views_ok = False
assert imf_views_ok, 'openbb-imf not installed or outdated'

Try / catch

try:
    fig, content = views.economy_shipping_chokepoint_info(**kwargs)
except RuntimeError as e:
    if str(e) == 'Unable to import the required module.' and e.__cause__:
        raise RuntimeError(f'install openbb-imf: {e.__cause__!r}') from e
    raise

Prevention

When it happens

Trigger: openbb-imf not installed in the environment (the economy extension is present but the IMF provider package is not); version skew where openbb-economy expects a view function that the installed openbb-imf no longer exposes.

Common situations: Partial OpenBB installs (pip install openbb without provider extras), upgrading one extension but not its provider package, or Docker images trimmed of optional dependencies.

Related errors


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