When I change/add a variable to my config.py
file and then try to import it to my Jupyter Notebook I get:
ImportError: cannot import name 'example_var' from 'config'
config.py:
example_var = 'example'
jp_notebook.ipynb:
from config import example_var print(example_var)
But after I restart the Jupyter Kernel it works fine until I modify the config.py
file again. I read somewhere that it’s because jupyter already cached that import. Is there any other way to delete that cache so I don’t have to restart the kernel every time I make a change in the config.py
file. Thanks for help in advance.
Advertisement
Answer
You can use autoreload to reload modules every new cell execution.
%load_ext autoreload %autoreload 2 from config import example_var print(example_var)