import Image vs from PIL import Image vs import PIL.Image
Bengt Richter
bokr at oz.net
Mon Nov 4 01:36:09 EST 2002
On Sun, 3 Nov 2002 21:42:11 -0800, Brian Lenihan <brian_ at yahoo.com> wrote:
>In article <aq4uo1$68o$0 at 216.39.172.122>, bokr at oz.net says...
>> 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.
>
>The examples assume you have a PIL.pth file in site-packages.
>
>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
><module '_imaging' from 'C:\Python22\lib\site-packages\PIL_imaging.pyd'>
>>>>
>
>C:\Python22\Lib\site-packages>cat PIL.pth
>PIL
Thanks, but that wasn't the problem. I had caused it with hacking detritus.
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
<module '_imaging' from 'D:\python22\lib\site-packages\PIL\_imaging.pyd'>
>>> ^Z
[22:20] C:\pywk\pilt>cat D:\python22\lib\site-packages\PIL.pth
PIL
But I notice an interesting difference in the name and place of the dll. Yours
is right under site-packages\ as PIL_imaging.pyd and mine is under
site-packages\PIL\ as _imaging.pyd. Did you install via the binary installer?
BTW, if the effbot is lurking, I would offer a patch to Image.py which would
have made what I did to myself more obvious:
--- D:\pilbuild\Imaging-1.1.3\PIL\Image.py Thu Mar 14 11:55:04 2002
+++ D:\Python22\Lib\site-packages\PIL\Image.py Sun Nov 03 22:07:31 2002
@@ -35,8 +35,13 @@
class _imaging_not_installed:
# module placeholder
+ def __init__(self, reason):
+ self.reason = reason
def __getattr__(self, id):
- raise ImportError, "The _imaging C module is not installed"
+ raise ImportError(
+ "The _imaging C module is not installed because:\n"
+ "%s" % self.reason
+ )
try:
# give Tk a chance to set up the environment, in case we're
@@ -53,8 +58,8 @@
import _imaging
core = _imaging
del _imaging
-except ImportError:
- core = _imaging_not_installed()
+except ImportError, e:
+ core = _imaging_not_installed(str(e))
import ImagePalette
import os, string, sys
Regards,
Bengt Richter
More information about the Python-list
mailing list