microsoft/qlib · error · FileNotFoundError
file "{}" does not exist
Error message
file "{}" does not exist What it means
parse_backtest_config (qlib/rl/contrib/naive_config_parser.py:28) loads a qlib.rl backtest configuration from .py/.json/.yaml/.yml files. check_file_exist first resolves the path to an absolute path and raises FileNotFoundError('file "<path>" does not exist') when os.path.isfile is false — i.e. the file is missing, is a directory, or the path is wrong.
Source
Thrown at qlib/rl/contrib/naive_config_parser.py:28
from ruamel.yaml import YAML
DELETE_KEY = "_delete_"
def merge_a_into_b(a: dict, b: dict) -> dict:
b = b.copy()
for k, v in a.items():
if isinstance(v, dict) and k in b:
v.pop(DELETE_KEY, False)
b[k] = merge_a_into_b(v, b[k])
else:
b[k] = v
return b
def check_file_exist(filename: str, msg_tmpl: str = 'file "{}" does not exist') -> None:
if not os.path.isfile(filename):
raise FileNotFoundError(msg_tmpl.format(filename))
def parse_backtest_config(path: str) -> dict:
abs_path = os.path.abspath(path)
check_file_exist(abs_path)
file_ext_name = os.path.splitext(abs_path)[1]
if file_ext_name not in (".py", ".json", ".yaml", ".yml"):
raise IOError("Only py/yml/yaml/json type are supported now!")
with tempfile.TemporaryDirectory() as tmp_config_dir:
with tempfile.NamedTemporaryFile(dir=tmp_config_dir, suffix=file_ext_name) as tmp_config_file:
if platform.system() == "Windows":
tmp_config_file.close()
tmp_config_name = os.path.basename(tmp_config_file.name)
shutil.copyfile(abs_path, tmp_config_file.name)
View on GitHub (pinned to 79633dd950)
Solutions
- Verify the file exists with os.path.isfile(path) before calling parse_backtest_config
- Use an absolute path (e.g. Path(__file__).parent / 'config.yaml') instead of a cwd-relative path
- Check for typos in the filename and ensure you are not passing a directory
- Download/restore the config file if it is part of examples/data not shipped with the package
Example fix
# before
config = parse_backtest_config('examples/rl/config.yaml') # may not exist relative to cwd
# after
from pathlib import Path
cfg_path = Path(__file__).resolve().parent / 'config.yaml'
assert cfg_path.is_file(), f'missing config: {cfg_path}'
config = parse_backtest_config(str(cfg_path)) Defensive patterns
Strategy: validation
Validate before calling
import os
abs_path = os.path.abspath(path)
if not os.path.isfile(abs_path):
raise FileNotFoundError(f'backtest config not found: {abs_path}') Try / catch
try:
cfg = parse_backtest_config(path)
except FileNotFoundError as e:
raise ValueError(f'check cwd={os.getcwd()} and the config path') from e Prevention
- Resolve config paths relative to the script file, not the shell cwd
- Fail early with isfile checks in CLI wrappers
When it happens
Trigger: Calling parse_backtest_config(path) where path points to a nonexistent file (typo, wrong working directory since the path is made absolute relative to cwd, or a directory path); passing a relative path from a different working directory.
Common situations: Running RL backtest examples with example config paths relative to the repo root while cwd is elsewhere; moved/renamed config files; missing 'default_config.yaml' in examples; typos in CLI arguments.
Related errors
- Only py/yml/yaml/json type are supported now!
- method {method} is not supported!
- This type of input {rtype} is not supported
- Can't find the BASE_CONFIG file: {base_config_path}
- Cannot find config file {}
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/3ec4596334e0e852.
Report an issue: GitHub.