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

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

img = plt.imread(f’{PATH}valid/cats/{files[0]}’)

when i ran these lines i got the following error

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

i googled the problem and the closest solution i got was to “import PIL.Image” which i did and i still got the same error.

i’m using windows 10.

without this step i cant go any further . so i request you guys to help me
thank you

1 Like

I had similar issue. Next time, you start your colab VM, be sure to comment out the following two lines (i.e do not run them)

#%reload_ext autoreload        <------------— comment out 
#%autoreload 0                 <------------— comment out
%matplotlib inline

Just to be safe, I also reinstalled my PIL

!pip install --no-cache-dir -I pillow

Hopefully, that will take care of the issue.


I also spent the few hours searching, for the cause. I think now that I have found the issue. There is actually no function with the name register_extensions() but register_extension(). I have created the PR on the official GitHub Repository. Let’s hope for the best.
I think it is the cause of the error.:sunglasses:

Which module was causing this error? Could you please provide a link to your PR @shubham827 ?

The error I am getting is AttributeError: module 'PIL.Image' has no attribute 'register_extensions'
There are others also who are facing the same issue

Well it turns out that the code for which I created the PR is indeed correct. Please see the PR for further info.

Is this only happening on Google Colab?

I have used Google Colab only and facing the same error.

Adding the following lines right before the imports cell fixed the problem for me

!pip install Pillow==4.0.0
!pip install PIL
!pip install image
import PIL.image


@kelawaad I have used the above lines with PIL.Image even then I am getting the same error.
I saw these lines while importing, torchvision is installing the Pillow 5.0.0 so whats the use of first line.

Installing collected packages: pillow, torchvision
  Found existing installation: Pillow 4.0.0
    Uninstalling Pillow-4.0.0:
      Successfully uninstalled Pillow-4.0.0
Successfully installed pillow-5.0.0 torchvision-0.2.0

Can you confirm your pillow version using
!pip show pillow

@jeremy I have tried it on Kaggle Kernels too but it crashes. Google CoLab keeps giving this error.

@shubham827 Pillow version is 4.0.0 and is verified by running

!pip show pillow


Name: Pillow
Version: 4.0.0
Summary: Python Imaging Library (Fork)

Did you run !pip install Pillow=4.0.0 after running !pip install torchvision?


No, I used them as you said in your comment before the imports.
But now I have used it after torchvision and now it is solved.
Thank you

1 Like

I typically use scipy.misc.imread instead of plt.imread.

And early on i do a
import scipy.misc

I also ran into this issue while using colab.
I think the problem is that Pillow==4.0.0 is preinstalled on colab and when you upgrade the package or install packages that require a newer version (5.0.0 in my case) there can be a mismatch between the api of the two versions.
For me restarting the runtime using “Runtime / Restart runtime…” from the menu after installing the newer Pillow using pip and running the code that uses it fixed the issue.


Another workaround:

def register_extension(id, extension):
    PIL.Image.EXTENSION[extension.lower()] = id.upper()
PIL.Image.register_extension = register_extension
def register_extensions(id, extensions):
    for extension in extensions:
        register_extension(id, extension)
PIL.Image.register_extensions = register_extensions

Hi all,

I’ve been trying different workarounds and even used some of the member’s helpful comments here, but I am still getting this error. I’ve also managed to “break” some other things, but I’m sure I can fix those with a fresh instance. Any and all help debugging is greatly appreciated.

Thanks everyone

Thanks! This fixed it for me too!

@lefant thanks for the solution… I can confirm restarting the runtime resolves this issue.

This workaround seems to fix it for me

1 Like

This one worked for me with a minor change as following:

def register_extension(id, extension):
    Image.EXTENSION[extension.lower()] = id.upper()
Image.register_extension = register_extension
def register_extensions(id, extensions):
    for extension in extensions:
        register_extension(id, extension)
Image.register_extensions = register_extensions
1 Like

I found that simply restarting runtime after installing the required packages at the top solved the issue for me.