3

I am using a jupyter lab notebook and trying to modify code, reload it within the jupyter notebook and use the modified code without reloading the kernel. I am using python 3.5.5 and am running code like this:

(in file test.py)

def myTest():
    print('hello')

(in jupyter)

from test import myTest
import importlib
importlib.reload(test)
myTest()

When I run the code in my jupyter lab notebook I get a NameError that name 'test' is not defined. From searching on stackoverflow the only references I find to this error is problems using older version of python. But the way I am using importlib.reload() seems to be correct.

3
  • 1
    Where are you defining test? myTest appears to be defined Commented Mar 20, 2018 at 20:27
  • maybe you did from test import myTest. Commented Mar 20, 2018 at 20:28
  • right sorry forgot that part; fixed the question Commented Mar 20, 2018 at 20:31

1 Answer 1

9

Have you tried the built-in magic command autoreload?

At the beginning of your notebook, add:

%load_ext autoreload
%autoreload 2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.