#StackBounty: #jupyter-notebook #reload reload does not work in jupyter notebook, but works in Ipython

Bounty: 50

I use Anaconda a lot, both jupyter notebook and spyder. Here is my python version:
Python 3.7.6 .
After I modified some module written by myself, reload always works in spyder’s Ipython console, but does not work in jupyter notebook. Here is my reload code:

import imp

Here is what jupyter notebook react(It looks like reload works, but changes don’t update)

enter image description here

I also tried the following magic command :

%load_ext autoreload
%autoreload 2

Again, these same code work in spyder’s Ipython console, but don’t work most of the time (yet sometimes work, I can’t figure out when the commands work, but I had experienced twice successes) in jupyter notebook. This is the Error reported by jupyter notebook:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-27-209f44cf5dc0> in <module>
----> 1 get_ipython().run_line_magic('load_ext', 'autoreload ')
      2 get_ipython().run_line_magic('autoreload', '2')

D:Programsanaconda3libsite-packagesIPythoncoreinteractiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2315                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2316             with self.builtin_trap:
-> 2317                 result = fn(*args, **kwargs)
   2318             return result

<D:Programsanaconda3libsite-packagesdecorator.py:decorator-gen-65> in load_ext(self, module_str)

D:Programsanaconda3libsite-packagesIPythoncoremagic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    189         if callable(arg):

D:Programsanaconda3libsite-packagesIPythoncoremagicsextension.py in load_ext(self, module_str)
     31         if not module_str:
     32             raise UsageError('Missing module name.')
---> 33         res = self.shell.extension_manager.load_extension(module_str)
     35         if res == 'already loaded':

D:Programsanaconda3libsite-packagesIPythoncoreextensions.py in load_extension(self, module_str)
     78             if module_str not in sys.modules:
     79                 with prepended_to_syspath(self.ipython_extension_dir):
---> 80                     mod = import_module(module_str)
     81                     if mod.__file__.startswith(self.ipython_extension_dir):
     82                         print(("Loading extensions from {dir} is deprecated. "

D:Programsanaconda3libimportlib__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)

D:Programsanaconda3libimportlib_bootstrap.py in _gcd_import(name, package, level)

D:Programsanaconda3libimportlib_bootstrap.py in _find_and_load(name, import_)

D:Programsanaconda3libimportlib_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'autoreload '

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.