What happens to PIL and import

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 until recently, I just blew it off as unimportant. However, I built a PIL under my virtual window in the windows and all of a sudden

 from PIL import Image 

no longer works i have to use

 import Image 

So now I want to understand why and what is happening.

I originally used the PIL installed with the Windows installer . But I needed read support for Group4 facsimile messages , so I made mods and then got a PIL for building and installing under virtualenv on windows (something trivial in linux and PITA on windows). But now I need to use the second form of import, although pip freeze shows that PIL==1.1.7 installed.

How is it that the first form of import does not work, although the PIL seems to be installed, and the second form works (and the PIL code works), indicating that it is installed, but does not appear in the PIL.

+4
source share
1 answer

Change From the comment on my @cgohlke answer, this will change in PIL1.2 :

support for importing from the standard namespace [has been removed]; PIL now lives only in the PIL namespace


I think Django's comment is pretty clear:

 # Try to import PIL in either of the two ways it can end up installed. 

PIL can be installed as one package, and you get access to the modules inside it:

 from PIL import ImageFile as PILImageFile 

or each module can be installed separately:

 import ImageFile as PILImageFile 

So, PIL is installed, it just breaks down into its component modules.

This is also a problem in The problem of 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 first piece of code will start:

 >>> import Image 

not from PIL import Image .

I agree that this is confusing behavior, but I think it is a relatively large package, so they might think that it does not need to deal with an additional level of depth.

This is apparently a problem in Python - the package installed with easy_install was not detected (PIL 1.1.7) , although it turned out that only the last responder understood, other people do not know what is happening.

+4
source

All Articles