nautechsystems/nautilus_trader · error · ImportError

pandas is required for visualization; install it with `pip i

Error message

pandas is required for visualization; install it with `pip install nautilus_trader[visualization]`

What it means

BetfairCredential::resolve found no username, password, or app key anywhere: nothing was supplied in the config and the environment variables BETFAIR_USERNAME, BETFAIR_PASSWORD, BETFAIR_APP_KEY could not produce a complete triple. The adapter needs all three to log in to the Betfair Identity API and obtain a session token, so building the credential fails before any connection attempt.

Source

Thrown at python/nautilus_trader/analysis/tearsheet.py:53

from nautilus_trader.core import NAUTILUS_VERSION
from nautilus_trader.core import unix_nanos_to_iso8601
from nautilus_trader.model import AggregationSource
from nautilus_trader.model import BarType


if TYPE_CHECKING:
    import pandas as pd

    from nautilus_trader.backtest import BacktestEngine
    from nautilus_trader.backtest import BacktestNode
    from nautilus_trader.backtest import BacktestResult


def _require_pandas():
    try:
        import pandas as pd
    except ImportError as e:
        raise ImportError(
            "pandas is required for visualization; install it with "
            "`pip install nautilus_trader[visualization]`",
        ) from e

    return pd


if not TYPE_CHECKING:

    class _PandasProxy:
        def __getattr__(self, name: str) -> Any:
            return getattr(_require_pandas(), name)

    pd = _PandasProxy()


try:
    import plotly.graph_objects as go

View on GitHub (pinned to a4b06ed870)

Solutions

  1. Export BETFAIR_USERNAME, BETFAIR_PASSWORD and BETFAIR_APP_KEY in the environment the node runs in
  2. Or pass username, password and app_key explicitly when building the config
  3. Add a preflight check that all three variables resolve before constructing the client

Example fix

# before: env empty, config fields unset
export BETFAIR_USERNAME=better
export BETFAIR_PASSWORD=secret
export BETFAIR_APP_KEY=xxxxxxx

# or entirely in config:
let config = BetfairDataClientConfig::builder()
    .username("better".into())
    .password("secret".into())
    .app_key("xxxxxxx".into())
    .build()?;
Defensive patterns

Strategy: validation

Validate before calling

let missing: Vec<&str> = [
    ("BETFAIR_USERNAME", username.is_none() && std::env::var("BETFAIR_USERNAME").is_err()),
    ("BETFAIR_PASSWORD", password.is_none() && std::env::var("BETFAIR_PASSWORD").is_err()),
    ("BETFAIR_APP_KEY", app_key.is_none() && std::env::var("BETFAIR_APP_KEY").is_err()),
]
.iter().filter(|(_, missing)| *missing).map(|(k, _)| *k).collect();
anyhow::ensure!(missing.is_empty(), "missing Betfair credentials: {missing:?}");

Type guard

fn betfair_credentials_resolvable() -> bool {
    std::env::var("BETFAIR_USERNAME").is_ok()
        && std::env::var("BETFAIR_PASSWORD").is_ok()
        && std::env::var("BETFAIR_APP_KEY").is_ok()
}

Prevention

When it happens

Trigger: Creating BetfairDataClientConfig/BetfairExecutionClientConfig with no credential fields while none of the three BETFAIR_* variables are set in the process environment; running under systemd, Docker, or CI where the variables were never exported into that process.

Common situations: Env vars set in an interactive shell but missing in CI, Docker, or cron; .env file not loaded by the runner; variable-name typos such as BETFAIR_API_KEY; fresh machine or new deployment without credential setup.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16). Data as JSON: /api/errors/f0be7d47b08ef581. Report an issue: GitHub.