Conor Egan
Conor Egan

Reputation: 469

How do I uninstall PIL for python 2.7 and use Pillow instead?

I have been searching for hours and can't find anything so I thought I'd ask here.

So my issue is with PIL and Pillow. I need to use python 2.7 as I'm using SimpleCV which isn't supported in Python 3 yet.

When I try to uninstall PIL using sudo pip uninstall PIL it outputs: Cannot uninstall requirement PIL, not installed.

This works for python 3 and allows me to use Pillow using from PIL import Image. If I try to use import Image I get an error because it doesn't exist however, for python 2.7 (the version I need to use), both from PIL import Image and import Image work making me believe PIL hasn't been uninstalled from python 2.7.

Am I correct in thinking that it hasn't been uninstalled for python 2.7? If so how do I uninstall it? Or is it something else?

Thanks in advance!

PS: Just in case it matters, I'm using a Raspberry Pi.

Upvotes: 11

Views: 23286

Answers (2)

David Lipschitz
David Lipschitz

Reputation: 152

Thanks for all this.

I still have OSX 10.13.6 High Sierra. Not sure if this was part of my problem or if the above is only for Windows, although I have used pip on my Mac?

I had to do the following:

brew upgrade # this took about half an hour

brew install Pillow # this took over 2 hours (not sure how long it actually took, but I went to sleep late last night after watching the install for a while).

There were some errors and I had to:

rm /usr/local/bin/2to3 brew link --overwrite [email protected]

I've also just linked python to python3.9 so that I don't have to keep typing python3 <filename.py>, ie:

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

allows me to type python <filename.py>

Then close and reopen the terminal for these changes to be effected, and I was in VS Code when I did the brew install, so I had to close and reopen VS Code as well.

See https://itsmycode.com/python-importerror-no-module-named-pil-solution/

Note that "pip uninstall PIL" failed on my Mac, so I assume it wasn't installed the first place, but I did already have HomeBrew installed.

https://pillow.readthedocs.io/en/stable/installation.html

https://brew.sh/

Note that after doing this whole install I had to reinstall Django, ie

pip3 install Django

Upvotes: 0

OptimusCrime
OptimusCrime

Reputation: 14863

I suspect you have successfully uninstalled PIL, and that you in fact have Pillow installed. Pillow is installed under the package name PIL. This allows you to swap out Pillow with PIL without having to rewrite any of your code. Pillow is "just" a PIL fork.

You can check if import PIL actually loads Pillow by doing:

import PIL
print PIL.PILLOW_VERSION

If you have Pillow installed it should output some version. It says 3.3.1 here, but I am using Python3. If you do not have Pillow, but PIL, it should result in an error.

Update : You may now see a warning like :

<stdin>:1: DeprecationWarning: PILLOW_VERSION is deprecated and will be removed in a future release. Use __version__ instead.

In that case , try running :

print(__PIL.__version__)

Upvotes: 17

Related Questions