Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 518
dinesh kumar gangapatnam Avatar asked Jan 31 '18 17:01

dinesh kumar gangapatnam


2 Answers

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.

like image 185
Tom Hale Avatar answered Oct 20 '22 11:10

Tom Hale


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.

like image 34
Mohamed Jihad Avatar answered Oct 20 '22 09:10

Mohamed Jihad