84

I've seen this problem before with other people, but haven't found a fix.

All I'm trying to do is:

from scipy.misc import imread

and I get

/home1/users/joe.borg/<ipython-input-2-f9d3d927b58f> in <module>()
----> 1 from scipy.misc import imread

/software/Python/272/lib/python2.7/site-packages/scipy/misc/__init__.py in <module>()
     16 try:
     17     from pilutil import *
---> 18     __all__ += pilutil.__all__
     19 except ImportError:
     20     pass

NameError: name 'pilutil' is not defined

But it's fine when I do from pilutil import * on its own (no import error). Even .../site-packages/scipy/misc/pilutil.py exists so I've got no idea why this is failing.

joedborg
  • 17,651
  • 32
  • 84
  • 118

10 Answers10

75

If you have Pillow installed with scipy and it is still giving you error then check your scipy version because it has been removed from scipy since 1.3.0rc1.

rather install scipy 1.1.0 by :

pip install scipy==1.1.0

check https://github.com/scipy/scipy/issues/6212

user_3pij
  • 1,334
  • 11
  • 22
  • 10
    version `1.2.1` worked for me. Installed with `conda install -c anaconda scipy=1.2.1` – xiawi Oct 09 '19 at 09:35
  • is there proper way of having script >=1.3.0 and also Pillow as well ? because my script installed wit anaconda and when I did `pip install Pillow` it shows I already have it in my anaconda path. – ElleryL Nov 30 '19 at 04:38
  • Thank you! Your solution has fixed my issue with the following import: `from scipy.misc import toimage` – Prajwal Mar 01 '20 at 17:55
59

You might need to install PIL or Pillow.

Community
  • 1
  • 1
carrier
  • 32,209
  • 23
  • 76
  • 99
30

The method imread in scipy.misc requires the forked package of PIL named Pillow. If you are having problem installing the right version of PIL try using imread in other packages:

from matplotlib.pyplot import imread
im = imread(image.png)

To read jpg images without PIL use:

import cv2 as cv
im = cv.imread(image.jpg)
MasterJedi
  • 1,618
  • 1
  • 18
  • 17
  • 4
    You can improve your answer by adding some information, why this should work, when the import from scipy.misc fails. Short code or error dumps are flagged by the system as low-quality answers. – Mr. T Mar 31 '18 at 13:36
13

looking into the documentation it says scipy.misc.imread is deprecated. It says to install imageio, and to use imageio.imread instead. Works great!

user42362
  • 131
  • 1
  • 4
7

You can try from scipy.misc.pilutil import imread instead of from scipy.misc import imread

Please check the GitHub page : https://github.com/amueller/mglearn/issues/2 for more details.

Swaroop
  • 1,219
  • 3
  • 16
  • 32
7

Expanding on user_3pij's answer

If you want to work with a scipy version that is higher than 1.3.0 then, as instructed in the scipy's documentation of the imread function, we can use the imageio module instead.

To successfully use the imageio imread function in a way that replicates the functionality of scipy's imread you can follow the instructions described here (disclaimer: I haven't tried it myself yet)

Gal Avineri
  • 524
  • 5
  • 13
3

Scipy deprecated the image I/O functionality in v1.0 :

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

Using the imageio module:

img = imageio.imread(fina)

There may be some differences. See https://imageio.readthedocs.io/en/stable/scipy.html

Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61
TimSC
  • 1,459
  • 16
  • 20
2

you can use this answer.

In newer versions of scipy, imread has been removed. You can use imageio.imread instead.

import imageio
im = imageio.imread('example.png')

But if you want to use scipy, you have to use version 1.0 or 1.1. To do this, use the following command.

conda install -c anaconda scipy==1.0

Then to use "imread" you need to install Pillow.you can use below command for install pillow :

pip install pillow
Mohsen Navazani
  • 131
  • 1
  • 6
0

I received errors when trying to use

from scipy.misc import imread

I was able to remove the errors and use the above line by first installing numpy+mkl and then installing scipy from Christoph Gohlke's website.

For me this was:

pip install numpy-1.11.1+mkl-cp27-cp27m-win32.whl
pip install scipy-0.17.1-cp27-cp27m-win32.whl

You will need to pick the correct version of the whl's for your system.

Also, make sure the pip command installs the modules. If you have any 1 or more of these already installed, you might need to use pip to force a reinstall.

Community
  • 1
  • 1
user3731622
  • 4,844
  • 8
  • 45
  • 84
  • Do know where one can find information on which version of `Pillow` and and `scipy` are necessary for the import to work seamlessly? – Momchill Jun 07 '19 at 15:12
  • @Momchill I'm not sure right now. My advice would be to try to use conda to install pillow and scipy, check if the imports work, & look at versions conda installed. – user3731622 Jun 09 '19 at 09:18
-1

you have to import it like

from scipy import misc

it will work fine then.

parad0x
  • 105
  • 2
  • 4