{"record":{"id":"d0d89c2338e6f89a","repo":"nautechsystems/nautilus_trader","slug":"failed-to-import-config-module-config-module-name-d0d89c","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/live/src/python/node.rs","lineNumber":1797,"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":1779,"sourceCodeEnd":1815,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/python/node.rs#L1779-L1815","documentation":"Raised inside the config-instance factory when py.import(config_module_name) fails — the Python module that should contain the NautilusConfig subclass cannot be imported. The underlying ImportError is embedded in {e}.","triggerScenarios":"Providing a config_path like \"pkg.mod:MyConfig\" where pkg.mod is not importable: package not installed, wrong working directory, PYTHONPATH missing the project root, or a syntax error inside the module.","commonSituations":"Live node launched from a directory where the strategy package isn't on sys.path; venv without the user's package installed; typo in the module part of config_path; module raising on import (dep missing).","solutions":["Run python -c \"import <config_module_name>\" in the same env to reproduce the ImportError","Install the package (pip install -e .) into the venv running the node","Set PYTHONPATH (or launch from the package root) so the module resolves","Fix any import-time exception inside the module shown in the embedded traceback"],"exampleFix":"// before\nPYTHONPATH= ./node run --config-path myproj.cfg:StrategyConfig  # myproj not found\n// after\npip install -e . && ./node run --config-path myproj.cfg:StrategyConfig","handlingStrategy":"validation","validationCode":"import importlib\nimportlib.import_module(config_module_name)  # reproduce ImportError before node start","typeGuard":"def module_importable(name: str) -> bool:\n    import importlib.util\n    return importlib.util.find_spec(name) is not None","tryCatchPattern":"try:\n    node.add_strategy_from_config(cfg)\nexcept Exception as e:\n    if \"Failed to import config module\" in str(e):\n        print(\"Fix sys.path or install the package; module:\", config_module_name)\n    raise","preventionTips":["Install user packages (pip install -e .) in the venv that runs the node","Validate config module imports in a pre-flight script","Avoid modules with import-time side effects that can raise"],"tags":["python","import","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-14T05:17:10.506Z"}