microsoft/qlib · error · ValueError

Cannot find config file {}

Error message

Cannot find config file {}

What it means

Raised by UserManager.add_user when the YAML config file path passed in does not exist on disk. The user's model and strategy are built from this config (init_instance_by_config on config['model'] / config['strategy']), so the file must be readable before any user data folder is created.

Source

Thrown at qlib/contrib/online/manager.py:107

        )
        save_instance(
            self.users[user_id].model,
            self.data_path / user_id / "model_{}.pickle".format(user_id),
        )

    def add_user(self, user_id, config_file, add_date):
        """
        add the new user {user_id} into user data
        will create a new folder named "{user_id}" in user data path
            Parameter
                user_id : string
                init_cash : int
                config_file : str/pathlib.Path()
                   path of config file
        """
        config_file = pathlib.Path(config_file)
        if not config_file.exists():
            raise ValueError("Cannot find config file {}".format(config_file))
        user_path = self.data_path / user_id
        if user_path.exists():
            raise ValueError("User data for {} already exists".format(user_id))

        with config_file.open("r") as fp:
            yaml = YAML(typ="safe", pure=True)
            config = yaml.load(fp)
        # load model
        model = init_instance_by_config(config["model"])

        # load strategy
        strategy = init_instance_by_config(config["strategy"])
        init_args = strategy.get_init_args_from_model(model, add_date)
        strategy.init(**init_args)

        # init Account
        trade_account = Account(init_cash=config["init_cash"])

View on GitHub (pinned to 79633dd950)

Solutions

  1. Check the path exists before calling: pathlib.Path(config_file).resolve().exists().
  2. Use absolute paths for config_file when invoking add_user from scripts/cron.
  3. Verify the file was actually copied/mounted in the deployment environment (ls the directory).

Example fix

# before
um.add_user(user_id="u1", config_file="configs/u1.yaml", add_date=d)
# ValueError: Cannot find config file configs/u1.yaml

# after
import pathlib
cfg = pathlib.Path("configs/u1.yaml").resolve()
assert cfg.exists(), f"missing config: {cfg}"
um.add_user(user_id="u1", config_file=cfg, add_date=d)
Defensive patterns

Strategy: validation

Validate before calling

import pathlib
cfg = pathlib.Path(config_file).resolve()
if not cfg.is_file():
    raise FileNotFoundError(f"user config missing: {cfg}")
um.add_user(user_id=user_id, config_file=cfg, add_date=add_date)

Prevention

When it happens

Trigger: Calling um.add_user(user_id, config_file, add_date) with a wrong/typo'd path, a relative path resolved against the wrong working directory, or a path on an unmounted share.

Common situations: Running the online-serving scripts from a different cwd so relative config paths break; deploying to a server where the yaml was not copied; trailing whitespace or quotes in the path from shell interpolation.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/621672fe1c8e6b34. Report an issue: GitHub.