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:
JavaScript
x
2
1
example_var = 'example'
2
jp_notebook.ipynb:
JavaScript
1
4
1
from config import example_var
2
3
print(example_var)
4
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.
JavaScript
1
6
1
%load_ext autoreload
2
%autoreload 2
3
from config import example_var
4
5
print(example_var)
6