docs/guides/understanding_errors/import_star.md
You're probably on this page because you just saw an error like this one:
<div align="center"> <figure> </figure> </div>marimo raises this error you attempt to use import *.
In this example, x was already defined, and the subsequent cell raised an
error when we tried to run it. In your case, perhaps your variable is a loop
variable (i), a dataframe (df), or a plot (fig, ax).
* imports?Star imports are incompatible with marimo's git-friendly file format and reproducible reactive execution:
import * everywhere except at the top-level of a module.Even Python's official style guide discourages the use of import *, writing:
Wildcard imports (from <module> import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools.
What do I get in return?
By accepting this constraint on imports, marimo makes your notebooks:
As a bonus, you'll find that you end up with cleaner, reusable code.
Fixing this error is simple: just import the module, and use . notation
to access its members.
import math
math.pi
instead of
from math import *
pi