fabio
fabio

Reputation: 1365

How to import Image in Python3.5 under windows from PIL/Pillow

I want to write a little app to convert some images. I think to have to use Image.open(), so I have to import the Image module. Right?

If so, here my problem. I have read other questions like this but any of them worked for me. I tried:

import Image => ImportError: cannot import name 'VERSION'

from PIL import Image => ImportError: cannot import name 'VERSION'

from Pillow import Image => ImportError: No module named 'Pillow'

In documentation I read:

Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.

Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead.

In my virtual enviroment I had PIL and Pillow directory but pip list gave only Pillow (3.1.0) so, even reading other answers, I try to uninstall PIL using pip but it can't find PIL, so I just delete the directory PIL and installed Pillow-PIL (now it appears on pip list and there's the directory Pillow_PIL on my venv\Lib\site-packages\) now:

import Image => ImportError: No module named 'PIL'

from PIL import Image => ImportError: No module named 'PIL'

from Pillow import Image => ImportError: No module named 'Pillow'

from Pillow-PIL import Image => SyntaxError: invalid syntax (on the minus sign)

from Pillow_PIL import Image => ImportError: No module named 'Pillow_PIL'

apt-get install python-imaging => "apt-get" command unknow (my free translation)

So, what now?

Edit: full error is

Traceback (most recent call last):
  File "prova.py", line 1, in <module>
    import Image
  File "D:\Python\Envs\possedimenti\lib\site-packages\Image.py", line 1, in <mod
ule>
from PIL.Image import *
  File "D:\Python\Envs\possedimenti\lib\site-packages\PIL\Image.py", line 29, in
 <module>
    from PIL import VERSION, PILLOW_VERSION, _plugins
ImportError: cannot import name 'VERSION'

Upvotes: 0

Views: 6080

Answers (1)

Artyer
Artyer

Reputation: 40836

When you install Pillow, it installs a module that you import as PIL. Pillow-PIL is apparantly a "Pillow wrapper for PIL compatibility".

It is generally not a good idea to delete files from site-packages, but to use a package installer like pip to do it.

To remedy this, I would suggest uninstalling Pillow-PIL, PIL (if you have it) and Pillow, and then reinstalling just Pillow.

pip3 uninstall Pillow-PIL ; pip3 uninstall PIL ; pip3 uninstall Pillow ; pip3 install Pillow

Upvotes: 3

Related Questions