A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: add error message when the imported module matches a filename (#4132)
Shahmir Varqha19b9d73ad4b4
diff --git a/marimo/_runtime/runner/cell_runner.py b/marimo/_runtime/runner/cell_runner.pyindex 8587126336..6f770204aa 100644--- a/marimo/_runtime/runner/cell_runner.py+++ b/marimo/_runtime/runner/cell_runner.py@@ -9,11 +9,13 @@ import signalimport threadingimport tracebackfrom dataclasses import dataclass+from pathlib import Pathfrom typing import TYPE_CHECKING, Any, Callable, Optional, Unionfrom marimo._ast.cell import CellImplfrom marimo._ast.variables import unmangle_localfrom marimo._config.config import ExecutionType, OnCellChangeType+from marimo._dependencies.dependencies import DependencyManagerfrom marimo._dependencies.errors import ManyModulesNotFoundErrorfrom marimo._loggers import marimo_loggerfrom marimo._messaging.errors import (@@ -431,6 +433,28 @@ class Runner:):self.missing_packages = True+ # If the user has a library and a file with the same name+ # we should inform that this is a conflict.+ if isinstance(unwrapped_exception, ModuleNotFoundError):+ try:+ module_name = getattr(unwrapped_exception, "name", "")+ # Grab the base module name if it's a submodule+ module_name = module_name.split(".")[0]++ if Path(+ f"{module_name}.py"+ ).exists() and DependencyManager.has(module_name):+ error_message = f"There is a file named '{module_name}.py' which conflicts with the imported package. Please rename the file."+ output = MarimoExceptionRaisedError(+ error_message,+ unwrapped_exception.__class__.__name__,+ None,+ )+ LOGGER.error(error_message)+ exception = output+ except Exception as e:+ pass+elif isinstance(unwrapped_exception, MarimoStopError):output = unwrapped_exception.outputexception = unwrapped_exception