ipython autoreload doesn't work

10,202

Sorry for the late response, I've just stumbled upon a similar problem.

In your run.ipynb, have you tried:

import pertussis
pertussis.check()

Or

%load_ext autoreload 
%autoreload 1

then

%aimport pertussis
check = pertussis.check  # optional shortcut
check()
Share:
10,202
DeanLa
Author by

DeanLa

Updated on July 05, 2022

Comments

  • DeanLa
    DeanLa almost 2 years

    autoreload doesn't work for me in subdirs at all.

    dir structure:

    run.ipynb
    oof.py
    pertussis/
        |-- __init__.py
    

    on run.ipynb I have (running with notebook):

    from pertussis import *
    check() #defined in the module
    

    this doesn't work. I tried everything. I added the autoreload magic inside code, inside config file, everywhere. I also added the folder of the module to the sys.path list. Never reloaded. I tried reloading a regular file oof.py from the notebook, instead of the module directly.

    on oof.py I have:

    from pertussis import *
    def check_2():
      print ("Hello")
    

    What happend now is that check_2 was autoreloaded successfully, but check from the module still didn't reload.

    Nothing seems to work, I am lost.

  • DeanLa
    DeanLa over 7 years
    I tried all of those. The reason is probably because ipython has a hard time doing deep-import. I moved all my sub modules into .py files instead of sub-folder with init.
  • pcko1
    pcko1 almost 5 years
    my class stopped being autoreloaded mysteriously when using %autoreload but using %aimport fixed it, thanks