marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
5.43k stars 165 forks source link

Unable to capture user-defined module updates #1542

Closed chenller closed 1 month ago

chenller commented 1 month ago

Describe the bug

If I create a file named tools.py, then I create a cell and run 'import tools', then I add a function to tools.py (such as def fun1()). Run the cell again, and the error 'AttributeError: module 'tools' has no attribute' fun1 'appears. It seems that Morimo cannot recognize the new changes in the file tools.py. If I don't use Notebook and instead use Marimo, this bug will severely limit the application of Marimo

Environment

marimo 0.6.13

Code to reproduce

cell1: import tools cell2: tools.fun1()

mscolnick commented 1 month ago

There is a setting "On module change":

Whether marimo should automatically reload modules before executing cells. If "lazy", marimo will mark cells affected by > module modifications as stale; if "autorun", affected cells will be automatically re-run.

What is your setting currently?

chenller commented 1 month ago

The function I expect is :

  1. When I import a module such as tools.py, if I modify tools.py, the imported module will not track the latest changes. It is "lazy".
  2. When I import a module such as tools.py, and then modify tools.py. When I run the code that imports the module again, the latest changes to the module will be loaded.

This means that morimo does not need to monitor module changes in real time, but only needs to re-import the module when I run the code to reload it. Marimo should not automatically reload modules before executing a unit of code. This behavior only occurs when encountering import xxx code execution.

mscolnick commented 1 month ago

This is how "lazy" operates. You can enable that with the setting in the top-right dropdown menu.

chenller commented 1 month ago

The problem I encountered is: The content of tools.py is

def fun1():
    print('fun1')
mscolnick commented 1 month ago

Can you copy your settings with: marimo config show

chenller commented 1 month ago

I have resolved this issue and thank you very much for your answer. Marimo is very user-friendly, and I will use it in future development.

qbilius commented 1 week ago

I'm facing the same issue (marimo 0.6.25). I tried both auto_reload = "autorun" and auto_reload = "lazy" but neither sees the changes in the imported module.

Update: It seems that the issue was related to the VS Code extension. When I updated it, autoreloading started working just fine.