[Numpy-discussion] A question about import in numpy and in place build
Robert Kern
robert.kern@gmail....
Fri Mar 13 01:05:37 CDT 2009
On Fri, Mar 13, 2009 at 00:42, David Cournapeau
<david@ar.media.kyoto-u.ac.jp> wrote:
> Hi,
>
> While making sure in-place builds work, I got the following problem:
>
> python setup.py build_ext -i
> python -c "import numpy as np; np.test()"
> -> many errors
>
> The error are all import errors:
>
> Traceback (most recent call last):
> File "/usr/media/src/dsp/numpy/git/numpy/tests/test_ctypeslib.py",
> line 83, in test_shape
> self.assert_(p.from_param(np.array([[1,2]])))
> File "numpy/ctypeslib.py", line 150, in from_param
> return obj.ctypes
> File "numpy/core/__init__.py", line 27, in <module>
> __all__ += numeric.__all__
> NameError: name 'numeric' is not defined
>
> Now, in the numpy/core/__init__.py, there are some "from numeric import
> *" lines, but no "import numeric". So indeed numeric is not defined. But
> why does this work for 'normal' numpy builds ? I want to be sure I don't
> introduce some subtle issues before fixing the problem the obvious way,
When it does work, the reason is because the import mechanism will
place the "numeric" module into the "numpy.core" namespace as soon as
it can, so it is usually available in the __init__ after a "from
numeric import *". nose tries to control imports a little more tightly
as it navigates packages looking for tests, so it can sometimes expose
corner cases like this.
In any case, it's okay to change the __init__.py's to be explicit
about doing both "import numeric" and "from numeric import *".
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion
mailing list