AttributeError: module 'PIL' has no attribute 'Image'

Hello everyone,

i just started going through lesson-1 in google-colab. As i was going through line by line along with the lecture video i was stuck when i came to these lines of code

data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=224, bs=bs)
data.normalize(imagenet_stats)

when i ran above lines i got the following error:

AttributeError: module ‘PIL.Image’ has no attribute ‘register_extensions

please, somebody help me, i got stuck at this point
thanku

I was able to get past this by commenting out the first two lines in the first cell of the notebook:

# %reload_ext autoreload
# %autoreload 2
%matplotlib inline
1 Like

it got fixed!
thanks @solomon

After you install fastai using the shell script, just restart the kernel. you can keep
%reload_ext autoreload
%autoreload 2
%matplotlib inline

1 Like

ohk, any idea why this error occurs in google colab plateform only?

My guess is that PIL is already installed in colab, but the script upgrades it and the new version get available only upon kernel restart.
It is a guess, anyway.
In other environments PIL is installed directly on the last version