{"record":{"id":"fb1a210f010aa0b4","repo":"nautechsystems/nautilus_trader","slug":"failed-to-import-config-module-config-module-name-fb1a21","errorCode":null,"errorMessage":"Failed to import config module {config_module_name}: {e}","messagePattern":"Failed to import config module (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/python/node.rs","lineNumber":518,"sourceCode":") -> anyhow::Result<Option<Bound<'py, PyAny>>> {\n    if config_path.is_empty() && config.is_empty() {\n        log::debug!(\"No config_path or empty config, using None\");\n        return Ok(None);\n    }\n\n    let config_parts: Vec<&str> = config_path.split(':').collect();\n    if config_parts.len() != 2 {\n        anyhow::bail!(\"config_path must be in format 'module.path:ClassName', was {config_path}\");\n    }\n    let (config_module_name, config_class_name) = (config_parts[0], config_parts[1]);\n\n    log::debug!(\n        \"Importing config class from module: {config_module_name} class: {config_class_name}\"\n    );\n\n    let config_module = py\n        .import(config_module_name)\n        .map_err(|e| anyhow::anyhow!(\"Failed to import config module {config_module_name}: {e}\"))?;\n    let config_class = config_module\n        .getattr(config_class_name)\n        .map_err(|e| anyhow::anyhow!(\"Failed to get config class {config_class_name}: {e}\"))?;\n\n    // Convert config dict to Python dict\n    let py_dict = PyDict::new(py);\n\n    for (key, value) in config {\n        let py_value = config_value_to_py(py, key, value)?;\n        py_dict.set_item(key, py_value)?;\n    }\n\n    log::debug!(\"Created config dict: {py_dict:?}\");\n\n    // Try kwargs first, then default constructor with setattr\n    let config_instance = match config_class.call((), Some(&py_dict)) {\n        Ok(instance) => {\n            log::debug!(\"Created config instance with kwargs\");","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/python/node.rs#L500-L536","documentation":"This error is raised by `create_config_instance` in the backtest node when importing the Python module that holds a component's configuration class fails. The library builds backtest nodes by dynamically importing a Python module and reading the config class from it; if `py.import(module_name)` returns an Err (module missing, broken, or raising on import), the underlying Python exception is wrapped with this message via anyhow. It is a module-resolution/import failure, not a config-value problem.","triggerScenarios":"Calling `create_importable_component`/`create_config_instance` with a `config_module_name` that is not importable: a typo'd dotted path, a module not on `sys.path`, a module that raises ImportError/SyntaxError/other exception at import time, or an installed package version that renamed or removed the module.","commonSituations":"Running a backtest from a script whose custom strategy/config module directory is not on PYTHONPATH; a package refactor renamed the config module (e.g. after a nautilus version upgrade); a custom module has an import-time error (bad import inside it, syntax error); missing optional dependency imported by the config module.","solutions":["Check the module path string for typos and confirm it matches the real dotted module path (e.g. `my_pkg.config`, not a file path)","Add the module's parent directory to PYTHONPATH or `sys.path` before creating the node, or install the package with `pip install -e .`","Run `python -c \"import <module>\"` in the same environment to see the real underlying import error (it is appended to this message)","If a dependency of the module is missing or the module raises at import time, fix that dependency/error; the wrapped `{e}` shows the cause"],"exampleFix":"// before\ncreate_importable_component(py, config, module=\"strategies.configs\", ...)  // module not on sys.path\n// after\nimport sys; sys.path.insert(0, \"/path/to/project\")  # or set PYTHONPATH\ncreate_importable_component(py, config, module=\"strategies.configs\", ...)","handlingStrategy":"try-catch","validationCode":"# Python-side pre-check before creating the node\nimport importlib\ndef module_importable(name):\n    try:\n        importlib.import_module(name)\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"match create_importable_component(...) {\n    Err(e) if e.to_string().contains(\"Failed to import config module\") => {\n        eprintln!(\"config module missing/unimportable: {e:#}\"); // fix sys.path or module\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Run `python -c \"import <module>\"` in the target environment before launching backtests","Keep config classes in installed packages (pip install -e .) rather than ad-hoc scripts","Set PYTHONPATH explicitly in launch scripts/CI","After upgrades, smoke-test module imports before running long backtests"],"tags":["python","module-import","backtest","config"],"backgroundTag":"module-init-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}