{"record":{"id":"07afc0053f2daa6a","repo":"nautechsystems/nautilus_trader","slug":"failed-to-import-module-name-e","errorCode":null,"errorMessage":"Failed to import {module_name}: {e}","messagePattern":"Failed to import (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/providers/instruments.rs","lineNumber":1790,"sourceCode":"    fn passes_filter_callable(&self, instrument: &InstrumentAny) -> anyhow::Result<bool> {\n        let Some(filter_callable) = self.config.filter_callable.as_deref() else {\n            return Ok(true);\n        };\n\n        #[cfg(feature = \"python\")]\n        {\n            use nautilus_model::python::instruments::instrument_any_to_pyobject;\n            use pyo3::{prelude::*, types::PyModule};\n\n            Python::attach(|py| {\n                let (module_name, callable_name) =\n                    filter_callable.rsplit_once('.').ok_or_else(|| {\n                        anyhow::anyhow!(\n                            \"Invalid filter_callable path {filter_callable:?}; expected module.callable\"\n                        )\n                    })?;\n                let callable = PyModule::import(py, module_name)\n                    .map_err(|e| anyhow::anyhow!(\"Failed to import {module_name}: {e}\"))?\n                    .getattr(callable_name)\n                    .map_err(|e| anyhow::anyhow!(\"Failed to resolve {filter_callable}: {e}\"))?;\n                let py_instrument = instrument_any_to_pyobject(py, instrument.clone())\n                    .map_err(|e| anyhow::anyhow!(\"Failed to convert instrument to Python: {e}\"))?;\n                callable\n                    .call1((py_instrument,))\n                    .and_then(|result| result.extract::<bool>())\n                    .map_err(|e| anyhow::anyhow!(\"filter_callable {filter_callable} failed: {e}\"))\n            })\n        }\n\n        #[cfg(not(feature = \"python\"))]\n        {\n            let _ = instrument;\n            anyhow::bail!(\n                \"filter_callable {filter_callable:?} requires the Interactive Brokers adapter to be built with the python feature\"\n            );\n        }","sourceCodeStart":1772,"sourceCodeEnd":1808,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/providers/instruments.rs#L1772-L1808","documentation":"After splitting filter_callable, the module part is imported with PyModule::import inside Python::attach. This error wraps the Python ImportError when the module cannot be imported — it does not exist on sys.path or a transitive import inside it failed.","triggerScenarios":"filter_callable names a module that is not installed or not on sys.path (e.g. a custom module not present in the node's Python environment), or the module itself raises ImportError at import time.","commonSituations":"Running the trader from a different working directory so a local module isn't importable; custom filter module not added to the venv/PYTHONPATH; a typo in the module name; module imports a missing third-party package.","solutions":["Install the module or add its directory to PYTHONPATH / sys.path","Test 'python -c \"import <module_name>\"' in the same environment the trader runs in","Fix any ImportError raised inside the target module (check the wrapped {e} message)","Verify you are using the same venv/interpreter the nautilus node was launched with"],"exampleFix":"// before\nfilter_callable = \"my_filters.skip_fx\"  # my_filters not on sys.path\n// after\n// set PYTHONPATH=/path/to/project before launch, or\nfilter_callable = \"my_project.filters.skip_fx\"  # installed package","handlingStrategy":"try-catch","validationCode":"import importlib\ntry:\n    importlib.import_module(module_name)\nexcept ImportError as e:\n    raise RuntimeError(f\"filter module {module_name} not importable: {e}\")","typeGuard":null,"tryCatchPattern":"try:\n    run_with_filter(filter_callable)\nexcept Exception as e:\n    if \"Failed to import\" in str(e):\n        print(\"check PYTHONPATH / install module:\", e)\n    else:\n        raise","preventionTips":["Run the trader with the same venv where the filter module is installed","Test 'python -c \"import module\"' in the deployment environment before launching","Keep PYTHONPATH set or install custom filters as packages"],"tags":["python","import","configuration","path"],"backgroundTag":"class-not-found","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"}