You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Jupytext on a project with a nested structure, something like
__init__.py
util.py
foo/__init__.py
foo/bar.py
I run
PYTHONPATH=$PWD jupyter notebook
to launch Jupyter so that e.g.
import util
works inside foo/__init__.py.
The problem I'm seeing is that if I put the line
from foo.bar import baz
inside foo/__init__.py, then when I run foo/__init__.py in Jupyter, the module is imported twice, once as sys.modules['__main__'] and once as sys.modules['foo']. This is confusing and can lead to weird issues when you haven't saved your notebook, so the .py file on disk differs from the file you have loaded in Jupyter.
Is there a good way to deal with this problem? In this example, what we want is for foo/__init__.py to "know" that it is foo and not __main__ when we load it in Jupyter.
The text was updated successfully, but these errors were encountered:
kerrickstaley
changed the title
Using jupytext on
Using jupytext in a nested project can result in re-import of the current module
Jan 30, 2024
from the repo root. In the Jupyter UI that appears, open foo/__init__.py and run all cells. You can see that the code in foo/__init__.py is executed twice:
Thank you @kerrickstaley for reporting this. I am not sure how I can help with this. Would you get the same issue if you were to run foo/__init__.py in a different interpreter? If that issue is specific to Jupyter then maybe you want to make you script aware of whether it runs in Jupyter?
I'm using Jupytext on a project with a nested structure, something like
I run
to launch Jupyter so that e.g.
works inside
foo/__init__.py
.The problem I'm seeing is that if I put the line
inside
foo/__init__.py
, then when I runfoo/__init__.py
in Jupyter, the module is imported twice, once assys.modules['__main__']
and once assys.modules['foo']
. This is confusing and can lead to weird issues when you haven't saved your notebook, so the.py
file on disk differs from the file you have loaded in Jupyter.Is there a good way to deal with this problem? In this example, what we want is for
foo/__init__.py
to "know" that it isfoo
and not__main__
when we load it in Jupyter.The text was updated successfully, but these errors were encountered: