Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

autoupdate module in IPython / jupyter notebook

I wrote my own module which as the following structure:

mymodule/
├── __init__.py
├── part1.py
├── part2.py
├── part3.py
└── part4.py

To test my module I am using IPython and/or jupyter notebook (formerly Ipython Notebook). As usual I do the module import like

import mymodule

Let's say I edit some code in part2.py and want to use the updated version of my module. First I thought just re-importing the module by import mymodule would do the job, but it does not. To completely reload the module I have to close IPython's shell or restart jupyter's kernel and start again by importing mymodule.

However, reffering to the docs, IPython provides an auto-update function called autoreload which provides different modes and could be activated as follows:

%load_ext autoreload
%autoreload 1
%aimport mymodule

Using both of my snippets, I am importing mymodule like that:

%load_ext autoreload
%autoreload 1
%aimport mymodule

import mymodule

# let's do something with the module here

However, even with activated autoreload 1 or autoreload 2 neither IPython nor jupyter are doing what I expect them to do and I still have to quit IPython's shell or restart jupyter's kernel in order to use the edited code of part2.py which is part of mymodule.

What am I doing wrong? It seems that I did not get the point about how this should work.

like image 711
albert Avatar asked Aug 30 '15 22:08

albert


People also ask

How do I enable auto suggestions in Jupyter lab?

Access the Jupyter Menu You have auto-complete in Jupyter notebooks like you have in any other Jupyter environment. Simply hit the “Tab” key while writing code. This will open a menu with suggestions. Hit “Enter” to choose the suggestion.

What is Autoreload in IPython?

IPython extension to reload modules before executing user code. autoreload reloads modules automatically before entering the execution of code typed at the IPython prompt.

What is %% Writefile in Jupyter Notebook?

%%writefile magic command in regular Python I just read what this does. It writes the contents of a Jupyter Cell to the specified file.


1 Answers

Change %autoreload 1 to %autoreload 2 like dashesy said, old version or bug.

like image 200
wizzfizz94 Avatar answered Oct 23 '22 04:10

wizzfizz94