DEV Community


Posted on • Updated on


How to automatically reload code changes in IPython and how to set autoreload at startup? Cheatsheet

What is autoreload?
autoreload loads the respective module before executing the code.
Consider if one is working in vscode like this:

autoreload example

  • Code in the left hand side and executing the code in right hand side in IPython.
  • As the code is developed it is executed in the IPython terminal to check it correctness.
  • Without autoreload enabled one needs to reload the code into IPython every-time a change is made and it needs to be evaluated.

How to set autoreload at startup?

In Windows 10:

  1. Press Win+R keys --> get run dialog
  2. Type %USERPROFILE% and press enter
  3. Navigate to .ipython folder, if you don't see one, following steps doesn't help
  4. From there navigate to folder profile_default/startup
  5. Create a file named
  6. Copy paste following lines of code in that file:

    from IPython import get_ipython
    ipython = get_ipython() 
    if "__IPYTHON__" in globals(): 
        ipython.magic("load_ext autoreload") 
        ipython.magic("autoreload 2")
  7. Save the file and open ipython it shall now autoreload

In Ubuntu:

  1. Open a terminal and navigate to ~/.ipython/profile_default/startup
  2. Follow the last three steps as in windows 10.

Top comments (0)

An Animated Guide to Node.js Event Loop

>> Check out this classic DEV post <<