I find this code in Django:
# Try to import PIL in either of the two ways it can end up installed.
try:
from PIL import ImageFile as PILImageFile
except ImportError:
import ImageFile as PILImageFile
and up until recently, I just blew it off as unimportant. However I built PIL under my virtualenv in windows and all of a sudden
from PIL import Image
doesn’t work anymore, I have to use
import Image
So, now I want to understand why and what is going on.
Initially I was using PIL installed with the windows installer. But I needed read support for Group4 Faxes so I did the mods and then got PIL to build and install under virtualenv on windows (something that is trivial on linux and a PITA on windows). But, now I have to use the second form of import, even though pip freeze shows that PIL==1.1.7 in installed.
How is it that first import form doesn’t work even though PIL appears to be installed, and the second form works (and the PIL code is functioning), indicating it is installed, but doesn’t show up under PIL.
Edit: From the comment to my answer by @cgohlke, this will change in PIL1.2:
I think the Django comment is pretty clear:
PIL can either be installed as a single package, and you access the modules within it:
or the modules can each be installed separately:
So PIL is installed, it is just split up into it’s component modules.
It’s also the issue in The problem with installing PIL using virtualenv or buildout, and @Ignacio mentions in a comment that the PIL tutorial actually expects it to be installed this way, the very first chunk of code starts:
not
from PIL import Image.I agree this is confusing behavior, but I guess it’s a relatively large package so they might think it’s easier to not have to deal with an extra level of depth.
This seems to be the problem in Python – package installed with easy_install is not being detected (PIL 1.1.7) although only the last answerer there figured it out, the rest of the people don’t know what is going on.