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

dinesh kumar gangapatnam picture dinesh kumar gangapatnam · Jan 31, 2018 · Viewed 22.5k times · Source

I was running lesson1 of fast.ai in google-colab. When I came to the line

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

plt.imshow(img);

It didn't show an image. Instead I got an error:

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

What could be causing this?

Answer

Tom Hale picture Tom Hale · Nov 27, 2018

I was on Google Colab when I encountered this issue.

After the code to install torch, add:

!pip install pillow==4.1.1
%reload_ext autoreload
%autoreload

The %autoreload will reload all modules so no kernel restart is required.

Credit goes to this forum post.