0

Several posts were advising to import Pillow using pip, after having uninstalled both PIL and Pillow, what i did :

python -m pip uninstall Pillow (worked)
python -m pip uninstall PIL (PIL was not installed)
python -m pip install Pillow (worked, i guess it was fine already)

Then, according to these posts, using "from PIL import Image" in python should work. I get the error "ImportError: No module named 'PIL'".

I tried "import Image" and "from Pillow import Image" but none of that works either. I'm on windows and using python 3.4.1.

Do you know what to do? Thanks

EDIT : pip had installed Pillow in anaconda3, and not in the python file I use. I copied/pasted the pillow egg file in site-packages and import PIL now works. However, from PIL import Image still does not work : i get ImportError: cannot import name 'Image'

EDIT : the problem was that the egg file was not working proerly (i think). I had to add my own python path to the paths in the environment variables, then i could install pillow with pip. But i now have another error.. from PIL import Image returns :

C:\Users\Loic\Documents\Python\pyzo2014a\lib\site-packages\PIL\Image.py in <module>()

     25 #

     26 

---> 27 from . import VERSION, PILLOW_VERSION, _plugins

     28 

     29 import logging

ImportError: cannot import name 'VERSION'

There is, indeed, no VERSION.py file in the PIL lib. Does that mean i've not installed it correctly? After having defined the python path and installed it with pip in cmd, everything should be fine...

Ashargin
  • 498
  • 4
  • 11
  • is there a folder in `Lib/site-packages` named `PIL`? If not, then it's not installed. – Dashadower Apr 22 '17 at 15:21
  • You're right, I see no folder corresponding. I searched for it though, and I found such a folder somewhere else in my computer. I copied/pasted it in sites-packages and did the same command again : `from PIL import Image`. Here is what i got : `File "C:\Users\Loic\Documents\Python\pyzo2014a\lib\site-packages\PIL\Image.py", line 56 except ImportError, v: ^ SyntaxError: invalid syntax` – Ashargin Apr 22 '17 at 16:07
  • Using a comma instead of `as` in `except` isn't allowed in python 3. Did you get the correct pillow version for python 3? – Dashadower Apr 22 '17 at 17:33
  • I concluded, as well, that the version was incorrect. Thus, i deleted this PIL file and copied/pasted the file pip had installed in anaconda (take a look at my edit above :) ) – Ashargin Apr 22 '17 at 17:46

1 Answers1

2

I'm on Linux so maybe it doesn't pertain to you, but for me python is Python2.7 and I have to use python3 to get Python3.5

jcomeau@aspire:/usr/src/myturnb$ pip3 install --user Pillow
Collecting Pillow
  Downloading Pillow-4.1.0-cp35-cp35m-manylinux1_i686.whl (5.5MB)
    100% |████████████████████████████████| 5.5MB 55kB/s 
Collecting olefile (from Pillow)
Installing collected packages: olefile, Pillow
Successfully installed Pillow-4.1.0 olefile-0.44
jcomeau@aspire:/usr/src/myturnb$ python3
Python 3.5.2 (default, Jul  5 2016, 11:33:36) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>>

VERSION is defined in __init__.py:

jcomeau@aspire:/usr/src/myturnb$ grep -r VERSION /home/jcomeau/.local/lib/python3.5/site-packages/PIL/ | grep -v '^Binary'
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/__init__.py:VERSION = '1.1.7'  # PIL version
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/__init__.py:PILLOW_VERSION = '4.1.0'  # Pillow
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/__init__.py:__version__ = PILLOW_VERSION
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/Image.py:from . import VERSION, PILLOW_VERSION, _plugins
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/Image.py:    if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/ImageCms.py:VERSION = "1.0.0 pil"
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/ImageCms.py:        VERSION, core.littlecms_version,
/home/jcomeau/.local/lib/python3.5/site-packages/PIL/ImageCms.py:        sys.version.split()[0], Image.VERSION
jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
  • Here is what i did : `C:\Users\Loic>python -m pip install pillow Collecting pillow Downloading Pillow-4.1.0-cp34-cp34m-win_amd64.whl (1.4MB) 100% |################################| 1.4MB 490kB/s Collecting olefile (from pillow) Using cached olefile-0.44.zip Installing collected packages: olefile, pillow Running setup.py install for olefile ... done Successfully installed olefile-0.44 pillow-4.1.0` the problem is, there is `from . import VERSION` in Image.py, but there is no VERSION.py file.. What you pointed out should not be the problem : we installed the same version, 4.1.0 – Ashargin Apr 22 '17 at 20:50
  • there's no VERSION.py necessary, it should be in `__init__.py`. I don't think it was installed correctly. – jcomeau_ictx Apr 22 '17 at 22:07
  • I uninstalled it, reinstalled it the exact same way, and it worked. I've no idea what was not working with the "from . import VERSION" line in Image.py. Or rather, i've no idea why it works now. – Ashargin Apr 22 '17 at 22:23