24

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.

Community
  • 1
  • 1
Whynot Ogle
  • 371
  • 2
  • 6

1 Answers1

75

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.

Daniel
  • 3,115
  • 5
  • 28
  • 39
Jomonsugi
  • 1,219
  • 1
  • 13
  • 21
  • 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 Aug 29 '17 at 09:58
  • @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. – Jomonsugi Aug 29 '17 at 15:43
  • 1
    That's what I've done ;) I found the answer, if anyone interested, here is the link: https://stackoverflow.com/questions/45939209/how-to-set-default-path-automatically-in-ipython – A.Joly Aug 29 '17 at 15:46
  • @A.Joly Outstanding. Thx! – Jomonsugi Aug 29 '17 at 15:50
  • 5
    It should be `c.InteractiveShellApp.exec_lines = ['%autoreload 2']`, because you already load the extension by adding it to `c.InteractiveShellApp.extensions` – x squared Nov 29 '18 at 16:41