import Image vs from PIL import Image vs import PIL.Image 
Author Message
 import Image vs from PIL import Image vs import PIL.Image

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



Fri, 22 Apr 2005 12:57:37 GMT  
 import Image vs from PIL import Image vs import PIL.Image

Quote:
> 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.

Quote:
>>> import Image
>>> Image.core

<module '_imaging' from 'C:\Python22\lib\site-packages\PIL_imaging.pyd'>

C:\Python22\Lib\site-packages>cat PIL.pth
PIL



Fri, 22 Apr 2005 13:42:11 GMT  
 import Image vs from PIL import Image vs import PIL.Image

Quote:
>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?

Never mind. I glitched it by having put a bad _imaging.pyd under \python22 along
the way. Removing it fixed the problem.

Regards,
Bengt Richter



Fri, 22 Apr 2005 13:45:13 GMT  
 import Image vs from PIL import Image vs import PIL.Image

Quote:


>> 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

 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:

     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



Fri, 22 Apr 2005 14:36:09 GMT  
 import Image vs from PIL import Image vs import PIL.Image

Quote:

> 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?

I built it myself.  Well, now I'm confused.  I removed PIL.pth and got
the same path you do.  I put PIL.pth back and still get the same path
you do.


Fri, 22 Apr 2005 15:55:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. displaying an Image using PIL w/o Image.show

2. from-import vs. import

3. importing graphical images into vw 2.0

4. Can't use imported image file

5. simple question, importing images

6. I want to import VRML- or STL-images in Labview

7. PixelTex 0.2 [generates pixelTexure nodes from imported images]

8. Can't import pygame.image

9. import images (wxPython)

10. Importing .gif or .jpg images to VW2.5

11. IMPORTING GRAPHIC IMAGES V/WIN

12. PIL 1.0 final - Python Imaging Library

 

 
Powered by phpBB® Forum Software