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 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.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/views/maritime_chokepoint_info.py:20
from openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData
def plot_chokepoint_annual_avg_vessels(
data: list[ImfMaritimeChokePointInfoData], theme="light"
):
"""Plot the average annual vessels for each chokepoint."""
# pylint: disable=import-outside-toplevel
import datetime # noqa
from openbb_core.app.model.abstract.error import OpenBBError
from pandas import DataFrame
try:
from openbb_charting.core.openbb_figure import OpenBBFigure
from plotly import graph_objects as go
from plotly.subplots import make_subplots
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, ImfMaritimeChokePointInfoData) for item in data)
):
raise OpenBBError(
"Invalid data format. Expected a list of ImfMaritimeChokePointInfoData."
)
if len(data) == 0:
raise OpenBBError("No data to plot.")
df = DataFrame([item.model_dump() for item in data])
if theme == "dark":
geo_bgcolor = "rgba(0,0,0,0)"View on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before: OpenBBError: Could not import Charting modules ... obb.economy.imf.maritime_chokepoint(chart=True) # after pip install openbb-charting obb.economy.imf.maritime_chokepoint(chart=True)
Defensive patterns
Strategy: validation
Validate before calling
# Verify charting is importable before enabling charts
def charting_available() -> bool:
try:
from openbb_charting.core.openbb_figure import OpenBBFigure # noqa
import plotly.graph_objects # noqa
return True
except Exception:
return False
chart = charting_available() Type guard
def charting_available() -> bool:
try:
from openbb_charting.core.openbb_figure import OpenBBFigure # noqa
import plotly.graph_objects # noqa
return True
except Exception:
return False Try / catch
from openbb_core.app.model.abstract.error import OpenBBError
try:
fig = plot_maritime_chokepoint_info(data, theme=theme)
except OpenBBError as e:
if 'Could not import Charting modules' in str(e):
pip_install_hint = 'pip install openbb-charting'
disable_charts() # degrade to table-only output
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not import Charting modules. Install with `pip install
- This charting method does not support {provider}. Supported
- Unable to import the required module.
- Invalid data format. Expected a list of ImfMaritimeChokePoin
- No data to plot.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/daa713d0385b2325.
Report an issue: GitHub.