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
- Run the command from the project root so the relative .py path resolves, or pass an absolute file path
- Install the package containing the module (pip install -e .) so import_module succeeds
- 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
- pip install -e . the package containing your app before launching the server
- Always launch from the project root, or pass absolute paths
- Verify module path spelling and that the printed fallback file path actually exists
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
- Error: The app file '{app_path}' does not exist
- Failed to load the file specs for '{file_path}'
- Error: The app file '{app_path}' does not contain an '{name}
- Error: The {name} instance in '{app_path}' appears not to be
- Error: The {name} instance in '{app_path}' is not an instanc
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/8d41b82866734e33.
Report an issue: GitHub.