How do I get ipython shell to auto-reload code?

87 views Asked by At

I'm using Python 3.9 with ipython 8.16.1. I would like my code to autoreload when I enter my shell using

python manage.py shell

but right now I have to enter the commands

> load_ext autoreload

and then

> autoreload

How do I configure the shell to do this auomtaically? I tried adding this to my shell_startup.py file

load_ext autoreload

but this results in this error when I start my shell ...

    load_ext autoreload
             ^
SyntaxError: invalid syntax
1

There are 1 answers

2
Suramuthu R On

ipython config file will be present in '.ipython/profile_default/'. The config file name will be either ipython_config.py or ipython_notebook_config.py or something similar. Search for "c.InteractiveShellApp.exec_lines" and "c.InteractiveShellApp.extensions". Change the above to the following respectively and uncomment.

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