IPython - Enhanced Interactive Python

dreload produces spurious traceback when numpy is involved

Reported by Fernando Perez on 2008-12-10
4
Affects Status Importance Assigned to Milestone
IPython
Invalid
Medium
Unassigned

Bug Description

Original report by Robin on the ipython user list is below.

I see the problem by using dreload(), but I can't reproduce it by manually calling the pieces of the code that break in that traceback. Will need to investigate further; there's a slim chance it's a problem in numpy's machinery that tries to detect that it's being imported from the build directory.

# Original report:
From: Robin <email address hidden>
Date: Fri, Dec 5, 2008 at 10:12 AM
Subject: [IPython-user] dreload numpy - source dir error
To: "<email address hidden>" <email address hidden>

Hi,

I thought I had seen this come up but I can't find it - so sorry if it has...

I have an error using dreload with numpy... I get the error about
importing numpy in the source directory whenever I try to dreload
something that uses numpy. For the most part it does seem to work (I'm
not changing numpy - its my own code I'm trying to dreload) but the
long trace back is a bit annoying because it breaks the list of
results when scrolling through the history...

Anyway here is an example:

robin-mbp:amaripool robince$ ipython
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
Type "copyright", "credits" or "license" for more information.

IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import numpy
In [2]: reload numpy
------> reload(numpy)
Out[2]: <module 'numpy' from
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/__init__.pyc'>
In [3]: dreload numpy
------> dreload(numpy)
Reloading numpy
Reloading numpy.numpy
Reloading numpy.show
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)

/Users/robince/phd/amaripool/<ipython console> in <module>()

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ipython-0.9.1-py2.5.egg/IPython/deep_reload.pyc
in reload(module, exclude)
   179 __builtin__.__import__ = deep_import_hook
   180 try:
--> 181 ret = deep_reload_hook(module)
   182 finally:
   183 __builtin__.__import__ = original_import

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ipython-0.9.1-py2.5.egg/IPython/deep_reload.pyc
in deep_reload_hook(module)
   157 name = module.__name__
   158 if '.' not in name:
--> 159 return import_module(name, name, None)
   160 i = name.rfind('.')
   161 pname = name[:i]

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ipython-0.9.1-py2.5.egg/IPython/deep_reload.pyc
in import_module(partname, fqname, parent)
   145
   146 try:
--> 147 m = imp.load_module(fqname, fp, pathname, stuff)
   148 finally:
   149 if fp: fp.close()

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/__init__.pyc
in <module>()
   119 its source directory; please exit the numpy source
tree, and relaunch
   120 your python intepreter from there."""
--> 121 raise ImportError(msg)
   122 from version import version as __version__
   123

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.

Cheers

Robin

eteq (erik-tollerud) wrote :

This is happening for me as well in 0.10 - it's pretty annoying in that it renders dreload (a very useful function) essentially useless. It doesn't even work to do dreload(somemodulethatusesnumpy,exclude=['numpy','numpy.numpy','numpy.show'])

Changed in ipython:
status: New → Triaged
importance: Undecided → Medium
jmulderr (jmulderr) wrote :

Still happens to me when using reload in 0.10

Fernando Perez (fdo.perez) wrote :

Sorry, we've moved all IPython bug tracking to github, this bug is now tracked here:

http://github.com/ipython/ipython/issues/32

Still, I'm afraid I don't have a solution. Patches welcome.

Closing here to prevent further confusion.

Changed in ipython:
status: Triaged → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers