OpenBB-finance/OpenBB · error · FileNotFoundError

Error: Neither module '{module_path}' could be imported nor

Error message

Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists

What it means

FileNotFoundError raised when an app path using module:attr colon notation cannot be resolved either way: importlib failed to import 'module_path' as a Python module, and the fallback that treats it as a local file (with .py appended) does not exist on disk. The message names both the module and the resolved absolute file path that was tried.

Source

Thrown at openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py:56

        return module

    # Case 1: Module path with colon notation (e.g., "my_app.main:app" or "main:app")
    if _is_module_colon_notation(app_path):
        module_path, name = app_path.rsplit(":", 1)
        try:  # First try to import as a module
            module = import_module(module_path)
        except ImportError:  # If module import fails, try to load as a local file
            if not module_path.endswith(".py"):
                module_path += ".py"

            if not Path(module_path).is_absolute():
                cwd = Path.cwd()
                file_path = str(cwd.joinpath(module_path).resolve())
            else:
                file_path = module_path

            if not Path(file_path).exists():
                raise FileNotFoundError(  # pylint: disable=raise-missing-from
                    f"Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists"
                )

            module = _load_module_from_file_path(file_path)

    # Case 2: File path (e.g., "main.py" or "my_app/main.py")
    else:
        if not Path(app_path).is_absolute():
            cwd = Path.cwd()
            app_path = str(cwd.joinpath(app_path).resolve())

        if not Path(app_path).exists():
            raise FileNotFoundError(f"Error: The app file '{app_path}' does not exist")

        module = _load_module_from_file_path(app_path)

    if not hasattr(module, name):
        raise AttributeError(

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Run the command from the project root so the relative .py path resolves, or pass an absolute file path
  2. Install the package containing the module (pip install -e .) so import_module succeeds
  3. Double-check the module path spelling and that a matching .py file (or package with __init__.py) exists at the printed location

Example fix

# before
openbb-mcp --app my_app.main:app   # run from wrong cwd, package not installed

# after
cd /path/to/project && openbb-mcp --app my_app.main:app
# or: pip install -e /path/to/project && openbb-mcp --app my_app.main:app
Defensive patterns

Strategy: validation

Validate before calling

from importlib.util import find_spec
from pathlib import Path

module_path = app_path.rsplit(":", 1)[0]
importable = find_spec(module_path) is not None
file_exists = Path(module_path if module_path.endswith(".py") else module_path + ".py").exists()
if not (importable or file_exists):
    raise ValueError(f"{module_path} is neither importable nor a local file")

Type guard

def app_module_resolvable(app_path: str) -> bool:
    from importlib.util import find_spec
    module_path = app_path.rsplit(":", 1)[0]
    if find_spec(module_path) is not None:
        return True
    candidate = module_path if module_path.endswith(".py") else module_path + ".py"
    return Path(candidate).exists()

Try / catch

try:
    app = import_app("my_app.main:app", "app")
except FileNotFoundError as e:
    if "Neither module" in str(e):
        # fall back to an explicit absolute file path
        app = import_app("/abs/path/to/my_app/main.py:app", "app")
    else:
        raise

Prevention

When it happens

Trigger: --app my_app.main:app where 'my_app' is not installed and no ./my_app/main.py exists relative to the CWD (relative paths are resolved against Path.cwd()). Also module typos, missing __init__.py for the intended package, or running the CLI from a directory where the source tree is absent.

Common situations: Running the MCP server from a different directory than the project root, forgetting to pip install -e the package that contains the app, virtualenv not activated so the module is not importable, file present but under a slightly different name than the module path implies.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/8d41b82866734e33. Report an issue: GitHub.