%reload_ext autoreload %autoreload 2 import sys, pickle file = "mytestclass.py" text = """ class Test(): def __init__(self): self.ok = 1 """ with open("mytestclass.py","w") as f: f.write(text) from mytestclass import * test = Test() # works p = pickle.dumps(test) # touch forces autoreloader to reload the library file !echo touch $file !touch $file # now it fails p = pickle.dumps(test) # cleanup !rm $file