freqtrade/freqtrade · error · ValueError

Directory '{directory}' does not exist.

Error message

Directory '{directory}' does not exist.

What it means

ValueError raised by `get_latest_result_file`-style helpers in bt_fileutils when the backtest-results directory passed in (e.g. `user_data/backtest_results`) does not exist. It is the first of three validation steps: directory exists → `.last_result.json` exists → contains the expected key.

Source

Thrown at freqtrade/data/btanalysis/bt_fileutils.py:72

    "funding_fees",
]


def get_latest_optimize_filename(directory: Path | str, variant: str) -> str:
    """
    Get latest backtest export based on '.last_result.json'.
    :param directory: Directory to search for last result
    :param variant: 'backtest' or 'hyperopt' - the method to return
    :return: string containing the filename of the latest backtest result
    :raises: ValueError in the following cases:
        * Directory does not exist
        * `directory/.last_result.json` does not exist
        * `directory/.last_result.json` has the wrong content
    """
    if isinstance(directory, str):
        directory = Path(directory)
    if not directory.is_dir():
        raise ValueError(f"Directory '{directory}' does not exist.")
    filename = directory / LAST_BT_RESULT_FN

    if not filename.is_file():
        raise ValueError(
            f"Directory '{directory}' does not seem to contain backtest statistics yet."
        )

    with filename.open() as file:
        data = json_load(file)

    if f"latest_{variant}" not in data:
        raise ValueError(f"Invalid '{LAST_BT_RESULT_FN}' format.")

    return data[f"latest_{variant}"]


def get_latest_backtest_filename(directory: Path | str) -> str:
    """

View on GitHub (pinned to 1c8edfe4d1)

Solutions

  1. Run a backtest with `--export trades` first so results and the directory exist
  2. Verify the directory: `ls user_data/backtest_results`
  3. Fix the path/typo passed via `--export-filename` or the helper's `directory` argument

Example fix

# before
freqtrade backtesting-show --export-filename /tmp/nope

# after
freqtrade backtesting --export trades
freqtrade backtesting-show --export-filename user_data/backtest_results/
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
d = Path('user_data/backtest_results')
if not d.is_dir():
    raise SystemExit(f'{d} missing — run a backtest with --export first')

Try / catch

try:
    fn = get_latest_backtest_filename(directory)
except ValueError as e:
    print(e)
    sys.exit(1)

Prevention

When it happens

Trigger: Calling `freqtrade backtesting-show` / `freqtrade webserver` analysis or the Python helpers with `--export-filename`/directory pointing to a non-existent path; `directory.is_dir()` is False.

Common situations: No backtest has ever been run (directory not created yet), custom `exportfilename` path typo, docker volume not mounted at the expected location.

Related errors


AI-assisted analysis of freqtrade/freqtrade@1c8edfe4d1 (2026-08-15). Data as JSON: /api/errors/b33218f232870710. Report an issue: GitHub.