import Image vs from PIL import Image vs import PIL.Image

Bengt Richter bokr at oz.net
Sun Nov 3 23:57:37 EST 2002


I seem to have succeeded in building PIL from source with jpeg and zlib 1.1.4
on windows NT. PIL and its pdf documentation manual are very nice (note that
if you're still using an old Acrobat 3 reader you will need to upgrade to
read the pdf manual).

I backtracked and took alternate routes and hacked here and there on the way
to the goal, so there were probably numerous places where something could have
gone wrong, but it seems to work if -- and here's where my question comes in --
I put 'from PIL ' in front of the import statements in documentation examples.

Googling reveals some discussions of similar symptoms in the past, but I didn't
find a solid diagnosis or suggestion in what I skimmed.

Hm... Not that I think I really want the available-for-import-using-a-plain-name
namespace to include a lot of stuff from various packages all the time. I may want
to use it just as an ordinary package anyway.

I think I'd rather work up some kind of mechansim to expose only what I'm interested
in at a given time, something like use_package('xxx') and then having site-packages/xxx
put temporarily in the search path. I haven't explored package use that much, so perhaps
there already is such a feature amongst the batteries?

I am running 2.2.2, and getting the following (separate invocations of Python to be sure):

 [20:43] C:\pywk\pilt>python
 Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import Image
 >>> Image.core
 <Image._imaging_not_installed instance at 0x007E20E0>
 >>> ^Z

The above obviously stops anything further from working, though it's easy to work around:

 [20:43] C:\pywk\pilt>python
 Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> from PIL import Image
 >>> Image.core
 <module 'PIL._imaging' from 'D:\python22\lib\site-packages\PIL\_imaging.pyd'>
 >>> ^Z


 [20:43] C:\pywk\pilt>python
 Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import PIL.Image
 >>> PIL.Image.core
 <module 'PIL._imaging' from 'D:\python22\lib\site-packages\PIL\_imaging.pyd'>
 >>> ^Z

I had to copy zlib.dll into the PIL directory so that _imaging.pyd would load
the latter ways, but I'm wondering why the import _imaging in Image.py is apparently
seeing things differently.

What did I glitch or omit? Or what is the explanation?

Regards,
Bengt Richter



More information about the Python-list mailing list