How to automatically reload modules in IPython?

Before starting, I want to say that I am not a programmer; I am a geek and an engineer. Thus, I like to code and use it academically. Stackoverflow taught me over 80% of what I know about python.

My problem is that I need to manually reload the modules in my scripts, first importing importlib into my terminal, and using importlib.reload(*modulename*) to reload them. I want my IPython terminal to automatically reload modules in my python scripts when I run them through my IPython terminal. This was functionally provided in the previous version using the magic %autoreload command, which doesn't seem to work for me.

I looked at the IPython documentation (link 1), tried using the %load_ext autoreload (link 2) and import ipy_autoreload , followed by the %autoreload 2 command (link 3). I found more than 4 other answers in stackoverflow telling me to do things in any link 2 or 3; it did not work for me. If anyone knows how to get the autoload back, it will make my fingers happier.

Link 1: https://ipython.org/ipython-doc/3/config/extensions/autoreload.html

Link 2: stack overflow

Link 3: stack overflow

I am using a 64-bit installation of Windows 7. I have IPython 4.0.1, which comes with my Anaconda3 installation (3.18.9 64 bit). Requests for my error tracing from the IPython terminal when I try to use %load_ext autoreload can be provided upon request.

+8
module ipython
source share
1 answer

All links that you have use commands in ipython. You should try to edit your configuration file. Open your terminal and follow these steps.

Step 1. Make sure you have the latest ipython installed

 $ ipython --version 

Step 2: find out where your configuration file is

 $ ipython profile create 

Step 3: Open the configuration file in the editor depending on the location of your configuration file. I use atom. For example:

 $ atom ~/.ipython/profile_default/ipython_config.py 

Step 4: Locate the following lines in the configuration file:

 c.InteractiveShellApp.extensions = [] 

change this to:

 c.InteractiveShellApp.extensions = ['autoreload'] 

and then uncomment this line

find:

 c.InteractiveShellApp.exec_lines = [] 

change this to:

 c.InteractiveShellApp.exec_lines = ['%autoreload 2'] 

and then uncomment this line

Done.

+20
source share

All Articles