[IPython-User] How to deep reload?
Tom Dimiduk
tdimiduk@physics.harvard....
Fri Feb 24 09:15:13 CST 2012
While on the topic of deep reloads, I have another question. How do you
do deep reloads of packages with imports of numpy?
For example if I use this script:
----------
test.py
----------
import numpy
a = numpy.zeros(1)
-------
And run
In [1]: import test
In [2]: dreload(test)
or
In [3]: dreload(test, exclude=['numpy', 'sys', '__builtin__', '__main__'])
I get the following error:
Reloading test
Reloading numpy
Reloading numpy.numpy
Reloading numpy.show
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/tdimiduk/playground/<ipython-input-2-38d07235c2de> in <module>()
----> 1 dreload(test)
/usr/local/lib/python2.7/dist-packages/IPython/lib/deepreload.pyc in
reload(module, exclude)
178 __builtin__.__import__ = deep_import_hook
179 try:
--> 180 ret = deep_reload_hook(module)
181 finally:
182 __builtin__.__import__ = original_import
/usr/local/lib/python2.7/dist-packages/IPython/lib/deepreload.pyc in
deep_reload_hook(module)
153 name = module.__name__
154 if '.' not in name:
--> 155 return import_module(name, name, None)
156 i = name.rfind('.')
157 pname = name[:i]
/usr/local/lib/python2.7/dist-packages/IPython/lib/deepreload.pyc in
import_module(partname, fqname, parent)
141
142 try:
--> 143 m = imp.load_module(fqname, fp, pathname, stuff)
144 finally:
145 if fp: fp.close()
/home/tdimiduk/playground/test.pyc in <module>()
----> 1 import numpy
2
3 a = numpy.zeros(1)
/usr/local/lib/python2.7/dist-packages/IPython/lib/deepreload.pyc in
deep_import_hook(name, globals, locals, fromlist, level)
34 # with from __future__ import absolute_import
35 parent = determine_parent(globals)
---> 36 q, tail = find_head_package(parent, name)
37 m = load_tail(q, tail)
38 if not fromlist:
/usr/local/lib/python2.7/dist-packages/IPython/lib/deepreload.pyc in
find_head_package(parent, name)
74 else:
75 qname = head
---> 76 q = import_module(head, qname, parent)
77 if q: return q, tail
78 if parent:
/usr/local/lib/python2.7/dist-packages/IPython/lib/deepreload.pyc in
import_module(partname, fqname, parent)
141
142 try:
--> 143 m = imp.load_module(fqname, fp, pathname, stuff)
144 finally:
145 if fp: fp.close()
/usr/lib/pymodules/python2.7/numpy/__init__.pyc in <module>()
125 its source directory; please exit the numpy source
tree, and relaunch
126 your python intepreter from there."""
--> 127 raise ImportError(msg)
128 from version import version as __version__
129
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and
relaunch
your python intepreter from there.
On 02/24/2012 10:04 AM, Jeremy Conlin wrote:
> On Thu, Feb 23, 2012 at 6:35 PM, Fernando Perez<fperez.net@gmail.com> wrote:
>> On Thu, Feb 23, 2012 at 9:38 AM, Jeremy Conlin<jlconlin@gmail.com> wrote:
>>> IPython seems to have changed how it does deep reloading of
>>> modules/packages. I can't seem to find information about how it is
>>> done in the documentation. Can someone show me the right way to to do
>>> it? I'm running IPython 0.12.
>> Mmh, we have not changed the dreload() command in many, many years, if
>> ever. What specifically do you see as a change? The dreload function
>> is called with a module:
>>
>> dreload(sys)
>>
>> and it will attempt to recursively reload all of its dependencies.
>> Note that dreload is fairly brittle, and it does *not* always work.
>> It's old and very delicate code that nobody has ever had the time to
>> dig into (it was written by Ka-Ping Yee years ago as a standalone
>> project, and we used it since IPython's start).
>>
>> But since I don't think we've changed anything regarding dreload(),
>> I'm curious as to what you are seeing.
> Thanks for the response. dreload() does seem to work. My memory was
> failing as I thought the command was deep_reload(). My bad.
>
> Jeremy
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
More information about the IPython-User
mailing list