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

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.

3 Likes

In my case (running on Google Colab) the latter didn’t work as is, I had to add:

from PIL import Image

and the complete thing (added after all the other setup has been completed)

# workaround 
from PIL import Image
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
4 Likes

Worked for me, thx.

It’s good workaround. Works for me.

not sure if anything changed on colab recently, but the same code I was using 1 or 2 weeks ago was working fine but recently running into the same issue. however, without any change or code, just simply restart the runtime, the problem resolved. Kind of feel it is caused by some library update/sync issue because I usually install PIL right before I ran my code.

Same, having problems in Colab and previous solutions do not appear to be working.

None of the above solutions worked for me, I found the way out by doing this:

!rm -rf /usr/local/lib/python3.6/dist-packages/PIL/
!rm -rf /usr/local/lib/python3.6/dist-packages/Pillow-4.0.0.dist-info/

restart the runtime after this, reinstall pillow with !pip install pillow

The Pillow version of 4.1.1 is the right package for running the model
pip install pillow==4.1.1

I have checked with examples also, all the models are working fine

Installing version 4.0.0 worked like a charm for me. just make you do this as the last step so that other libraries can’t upgrade this again

1 Like

This solution also worked for me.

+1 -> works for me too :slight_smile:

This solution worked very well for me on Google Colab! Thanks a lot!

well that solved the issue with some warnings and some errors as well on colab.

But thanks for sharing

Thanks a lot!:grinning:

I’m trying to deploy on EC2. None of these solutions have worked. Any other suggestions?

This solution helped me out in 2021 :slight_smile: