{"record":{"id":"6a853545433b10ba","repo":"nautechsystems/nautilus_trader","slug":"failed-to-import-module-module-name-e","errorCode":null,"errorMessage":"Failed to import module {module_name}: {e}","messagePattern":"Failed to import module (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/python/registration.rs","lineNumber":545,"sourceCode":"    let Some((module_name, class_name)) = path.split_once(':') else {\n        anyhow::bail!(\"{field} must be in format 'module.path:ClassName'\");\n    };\n\n    if module_name.is_empty() || class_name.is_empty() || class_name.contains(':') {\n        anyhow::bail!(\"{field} must be in format 'module.path:ClassName'\");\n    }\n\n    Ok((module_name, class_name))\n}\n\nfn import_python_class<'py>(\n    py: Python<'py>,\n    module_name: &str,\n    class_name: &str,\n) -> anyhow::Result<Bound<'py, PyAny>> {\n    let module = py\n        .import(module_name)\n        .map_err(|e| anyhow::anyhow!(\"Failed to import module {module_name}: {e}\"))?;\n\n    module\n        .getattr(class_name)\n        .map_err(|e| anyhow::anyhow!(\"Failed to get class {class_name}: {e}\"))\n}\n\nfn create_config_instance<'py>(\n    py: Python<'py>,\n    config_path: &str,\n    config: &HashMap<String, serde_json::Value>,\n) -> 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 Some((config_module_name, config_class_name)) = config_path.split_once(':') else {\n        anyhow::bail!(\"config_path must be in format 'module.path:ClassName', was {config_path}\");","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/python/registration.rs#L527-L563","documentation":"Raised by `import_python_class` when `PyModule::import` fails to import the named Python module while resolving an actor or strategy class from its config (module path + class name). This is a Python ImportError translated into an anyhow error, meaning the module could not be found or raised an error during import.","triggerScenarios":"Registering a Python actor/strategy via a config with `actor`/`strategy` given as `module:Class` string where the module name is misspelled, not on `sys.path`, or the module itself raises ImportError at import time (e.g. missing dependency inside it).","commonSituations":"Typo in module path in a trader/backtest JSON config; running from a different working directory so a local module isn't importable; missing third-party dependency imported by the strategy module; virtualenv not active.","solutions":["Verify the module name in the config matches the importable Python module path exactly","Run `python -c \"import <module>\"` in the same environment the trader uses to reproduce the ImportError","Fix the underlying ImportError (install missing packages, correct relative/absolute path)","Ensure the working directory / PYTHONPATH includes the package containing the module"],"exampleFix":"// before\n{\"actor\": \"my_stratPack.MyActor\"}   # module not importable\n// after\n{\"actor\": \"my_strategy.actors.MyActor\"}  # correct dotted module path","handlingStrategy":"validation","validationCode":"import importlib\nimportlib.import_module(module_name)  # raises early with a clear ImportError","typeGuard":null,"tryCatchPattern":"try:\n    trader.add_strategy(cfg)\nexcept Exception as e:\n    if \"Failed to import module\" in str(e):\n        logging.error(\"check module path and Python environment: %s\", e)\n    raise","preventionTips":["Test `python -c \"import my_module\"` in the exact runtime environment","Use fully qualified dotted module paths in configs","Activate the correct virtualenv before starting the trader"],"tags":["python","import-error","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"}