当我在config.py
文件中更改/添加变量,然后尝试将其导入到Jupyter Notebook中时,我得到:
ImportError: cannot import name 'example_var' from 'config'
config.py:
example_var = 'example'
jp_notebook.ipynb:
from config import example_var
print(example_var)
但是,在重新启动Jupyter内核之后,它可以正常工作,直到config.py
再次修改文件为止。我在某处读到这是因为jupyter已经缓存了该导入。还有什么其他方法可以删除该缓存,因此不必每次更改config.py
文件时都重新启动内核。预先感谢您的帮助。
您可以使用autoreload在每个新的单元执行中重新加载模块。
%load_ext autoreload
%autoreload 2
from config import example_var
print(example_var)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句