25

Before I begin, I want to say that I am not a programmer; I am a geek and an engineer. Thus, I love coding and use it academically. Stackoverflow taught me more than 80% of what I know about python.

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

I have looked @ the IPython documentation (link 1), tried using the %load_ext autoreload command (link 2) and the import ipy_autoreload followed by %autoreload 2 command (link 3). I found more than 4 other answers in stackoverflow telling me to do the things in either link 2 or 3; it didn't work for me. If anyone knows how to bring back autoreloading, it would make my fingers a bit happier.

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

Link 2: https://stackoverflow.com/a/18216967/5762140

Link 3: https://stackoverflow.com/a/4765191/5762140

I am using a 64 bit installation of Windows 7. I have IPython 4.0.1 which came with my installation of Anaconda3 (3.18.9 64bit). Screenies about my error traceback from the IPython terminal when i try to use %load_ext autoreload can be provided on request.

1 Answer 1

82

All the links you have above use commands within ipython. You should try editing your config file. Open up your terminal and complete the following steps.

Step 1: Make sure you have the latest ipython version installed

$ ipython --version

Step 2: find out where your config file is

$ ipython profile create

Step 3: Open the config file with an editor based on the location of your config file. I use atom. For example:

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

Step 4: Look for the following lines in the config file:

c.InteractiveShellApp.extensions = []

change it to:

c.InteractiveShellApp.extensions = ['autoreload']

and then uncomment that line

find:

c.InteractiveShellApp.exec_lines = []

change it to:

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

and then uncomment that line

Done.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, it works fine for me :). do you know how to set default starting directory for ipython ? I tried with c.InteractiveShell.ipython_dir but it doesn't seem to be the relevant option ...
@A.Joly I would be happy to try and answer your question, but as a best practice for StackOverflow, as your question pertains to a different topic, please first search for an answer already given to your question, and then if you can't find one, post a new question.
That's what I've done ;) I found the answer, if anyone interested, here is the link: stackoverflow.com/questions/45939209/…
@A.Joly Outstanding. Thx!
It should be c.InteractiveShellApp.exec_lines = ['%autoreload 2'], because you already load the extension by adding it to c.InteractiveShellApp.extensions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.