38

I open the python3 interpreter and type

import scipy.misc
scipy.misc.imsave

with the result

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'imsave'

Has the name changed? It works fine in python2 but I would rather not migrate backwards so to speak.

I have python 3.3.1 on Lubuntu 13.04 with all the modules downloaded from the default repositories. Scipy is installed and print(scipy.misc.__doc__) shows that imsave should be there.

EDIT:

scipy.__version__ gives 0.11.0

from scipy.misc import imsave gives

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name imsave
Cramer
  • 1,785
  • 1
  • 12
  • 20
  • what is `scipy.__version__` and what does `from scipy.misc import imsave` do? For that matter, what if you change `scipt.misc.imsave` to `scipy.misc.imsave`? – askewchan Nov 15 '13 at 01:31
  • 1
    I've added the results and fixed the spelling mistake. – Cramer Nov 15 '13 at 01:55
  • 1
    `scipy.misc.imsave` is from `pilutils` which depends on `PIL`. Do you have `PIL` installed? If so, it's probably worth upgrading `scipy`, which is at `0.13.0` now. Even if the upgrade isn't necessary, perhaps the re-installation is. – askewchan Nov 15 '13 at 02:02
  • newer duplicate question/answer, but with references: https://stackoverflow.com/a/57253092 – michael Jul 10 '20 at 03:05

4 Answers4

61

scipy.misc.imsave has been deprecated in newer Scipy versions.

Change your code to:

import imageio
imageio.imwrite('filename.jpg', array)
Ivona Tau
  • 1,032
  • 1
  • 10
  • 20
16

Or pip install pillow in order to install a new PIL implementation. This works well in Python 3.4.

Bohumir Zamecnik
  • 2,450
  • 28
  • 23
  • pillow needs some libraries as well, it won't necessarily work if you can't install OS packages. (--user) – Fábio Dias Oct 28 '16 at 20:27
  • 4
    I pip installed pillow without errors on windows 10 for python 3.7 (in a virtual environment). I still get `'scipy.misc' has no attribute 'imsave'` – cowlinator Aug 06 '19 at 01:14
5

Try installing the Ubuntu package python3-imaging. This packages provides PIL (the Python Imaging Library). PIL is required by imsave (and other im* functions in scipy.misc).

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214
5

I had the same problem and the answers to this question didn't help. I solved it by installing a previous version of scipy:

pip3 install scipy==0.17.0
grooveplex
  • 2,492
  • 4
  • 28
  • 30
KarolBorkowski
  • 145
  • 1
  • 9