33

I'm trying to use the ndimage library from scipy, but its apparently missing. I have run the tests from both numpy and scipy and the results were OK. I am using numpy 1.6.1 and scipy 0.10.0 installed from the official packages on sourceforge.

Running

import numpy
import scipy
import pprint

print(scipy.version.version)
print(numpy.version.version)

img = scipy.ndimage.imread("")

gives

0.10.0
1.6.1
Traceback (most recent call last):
  File "extract.py", line 8, in <module>
    img = scipy.ndimage.imread("")
AttributeError: 'module' object has no attribute 'ndimage'
Charles
  • 50,943
  • 13
  • 104
  • 142
davidtbernal
  • 13,434
  • 9
  • 44
  • 60

4 Answers4

65

You have to import the module:

import scipy.ndimage
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
davidtbernal
  • 13,434
  • 9
  • 44
  • 60
  • 1
    I have the same problem and got fixed now using your method. But in my ipython interpreter, after `import scipy`, using `scipy.ndimage.filters.gaussian_filter1d` does not throw errors. Why is that? – Shuai Zhang Feb 06 '15 at 08:12
  • See https://docs.scipy.org/doc/scipy/reference/index.html#guidelines-for-importing-functions-from-scipy for details – maggie Jun 23 '22 at 08:16
18

Modules should be imported like this:

from  scipy import ndimage
randomusername
  • 7,927
  • 23
  • 50
Rishi Ganesh V
  • 181
  • 1
  • 3
1

https://docs.scipy.org/doc/scipy-1.2.1/reference/generated/scipy.misc.imread.html

imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead.

Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
Beginner
  • 11
  • 4
-2

Locate the init file in scipy and add import ndimage