65

I updated from ubuntu 12.04 to ubuntu 12.10 and the python module I have written suddenly no longer works with the error message that the module scipy does not have the attribute 'misc'. This worked previously. I am still using python 2.7 after the update. Here is where the code crashes

import scipy
scipy.misc.imsave(slice,dat)

Any ideas?

moadeep
  • 3,988
  • 10
  • 45
  • 72
  • I found an equivalent function pylab.imsave which works. – moadeep Nov 27 '12 at 10:03
  • 3
    Related: [Why do Python modules sometimes not import their sub-modules?](http://stackoverflow.com/questions/3781522/why-do-python-modules-sometimes-not-import-their-sub-modules) – Garrett Oct 20 '14 at 05:40
  • Also check that you have **pillow**. Without **pillow** _imsave_ doesn't export. **pip install pillow** – im7mortal Jul 29 '17 at 00:00
  • https://stackoverflow.com/questions/61860317/how-u-can-fix-this-problem-attributeerror-scipy-object-scipy-has-no-attribu/61860318#61860318 – Engineer Ahmed IT May 18 '20 at 00:01

5 Answers5

92
>>> import scipy
>>> scipy.misc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'misc'
>>> 
>>> 
>>> import scipy.misc
>>> scipy.misc.imsave
<function imsave at 0x19cfa28>
>>>

Which seems to be quite common with scipy.

ev-br
  • 24,968
  • 9
  • 65
  • 78
  • 4
    @SibbsGambling for the why: Why do Python modules sometimes not import their sub-modules: https://stackoverflow.com/questions/3781522/why-do-python-modules-sometimes-not-import-their-sub-modules – Charlie Parker Sep 13 '17 at 20:04
9

Because you cannot directly use the misc module from scipy without explicitly import it. Here is the way of loading scipy.misc:

import scipy.misc

#Load the Lena image into an array, (yes scipy does have a lena function)
lena = scipy.misc.lena()
...
Jim Raynor
  • 2,268
  • 3
  • 31
  • 36
8

imread is depreciated after version 1.2.0 ! So to solve the problem I had to install 1.1.0 version.

 pip install scipy==1.1.0
mahbubcseju
  • 2,200
  • 2
  • 16
  • 21
  • 1
    imsave is also deprecated. It is recommended to use https://imageio.readthedocs.io/ now. https://docs.scipy.org/doc/scipy-1.1.0/reference/generated/scipy.misc.imsave.html – Atnas Nov 25 '19 at 15:46
  • If you are using Python 3.6, this fixes the problem. However, the problem cannot be fixed with recent Python versions (I tried with Python 3.9 with no luck) because that scipy version and `imsave` are deprecated, as @Atnas has pointed out. – DRTorresRuiz Jul 24 '21 at 17:09
3
  1. You need to explicitly import scipy.misc as:

    import scipy.misc

  2. You need to install the package pillow (formerly known as PIL), if not already installed. For image manipulation functions of scipy.misc such as imread() or imsave() to function correctly, pillow has to be installed. To verify, either run your code again or type the below command:

    scipy.misc.imread

Jim C
  • 1,785
  • 1
  • 13
  • 13
0

I had a similar problem. In my case, I was trying to import comb from scipy.misc, which had been depreciated in scipy 1.0.0 (see ref here). Thus, I was inevitabely getting AttributeError: module 'scipy.misc' has no attribute 'comb'.

Replacing scipy.misc.comb with scipy.special.comb fixed the issue.