[Numpy-discussion] numpy finding local tests on import?!?!
chris.barker at noaa.gov
Fri May 10 14:33:04 EDT 2019
This issue appears to have been fixed in numpy 1.15 (at least, I didn't
However, I also had some issues in my environment that I also fixed, so it
may be that numpy's behavior hasn't changed -- I don't have the energy to
And it doesn't hurt to have this in the archives in case someone else runs
into the problem.
Read on if you care about weird behaviour with the testing package in numpy
Numpy appears to be both running tests on import (or at lest the the
runner), and finding local tests that are not numpy's
I found this issue (closed without a resolution):
which is related -- but it's about the import time of numpy.testing, and
not about errors/issues from that import. But maybe the import process ahs
been changed in newer numpys
What I did, and what I got:
I am trying t debug what looks like a numpy-related issue in a project.
So one thing I did was try to import numpy and check __version__:
python -c "import numpy; print(numpy.__version__)"
very weird barf:
line 4, in <module>
File "time.py", line 7, in <module>
import netCDF4 as nc4
line 3, in <module>
from ._netCDF4 import *
File "include/netCDF4.pxi", line 728, in init netCDF4._netCDF4
AttributeError: 'module' object has no attribute 'ndarray
I get the same thing if I fire up the interpreter and then import numpy
as the error seemed to come from:
I had a hunch.
I was, in fact, running with my current working directory in the package
dir of my project, and there is a test package in that dir
I cd out of that, and presto! numy imports fine:
$ python -c "import numpy; print(numpy.__version__)"
OK, that's a kinda old numpy -- but it's the minimum required by my
project. (though I can probably update that -- I"ll do that soon)
So it appears that the test runner is looking in the current working dir
(or, I suppose sys.PATH) for packages called tests -- this seems like a
broken system, unless you are runing the tests explicitly from teh command
line, it shouldn't look in the cwd, and it probably shouldn't ever look in
all of sys.path.
BUt my bigger confusion here is -- why the heck is the test runner being
run at ALL on a simple import ?!?!?
If this has been fixed / changed in newer numpy's the OK -- I'll update my
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion