Roman
Roman

Reputation: 131228

How to force IPython to see an updated library?

I do the following in my IPython notebook:

import sys
sys.path.append('my_directory')
from db import *

It works fine. But then I added a new function to the db.py and IPython does not see it. It OK. But it does not see it even if I reset everything end re-execute the cell that imports everything. It does not see it even if I user reload. It does not see it even if I close the IPython notebook and restart it.

What is the way to force IPython (or python) to see the updated content of the file?

Upvotes: 2

Views: 1720

Answers (1)

nom-mon-ir
nom-mon-ir

Reputation: 3918

You need to use autoreload. Check the manual at http://ipython.org/ipython-doc/dev/config/extensions/autoreload.html. Seems you need:

%autoreload 2

The above will automatically reload all imported modules. Except those inlcuded in a separate special list of modules specified by %aimport modulename. Those will only be autoreloaded if you specify %autoreload 1.

Upvotes: 3

Related Questions