Discussion:
Question about ImageDraw.Draw function
Mark Shure
2003-08-26 19:04:57 UTC
Permalink
Hello,
import Image, ImageDraw
im = Image.open("lena.ppm")
draw = ImageDraw.Draw(im)
Traceback (most recent call last):
File "C:/Python22/imageDraw_test2.py", line 3, in ?
draw = ImageDraw.Draw(im)
File "C:\Python22\lib\site-packages\PIL\ImageDraw.py", line 72, in __init__
self.draw = Image.core.draw(self.im, blend)
AttributeError: 'module' object has no attribute 'draw'

I'm using Python 2.2.1 under Win2k with PIL 1.1.4 (binaries installed using "PIL-1.1.4.win32-py2.2.exe").

I haven't been able to find any leads on the web or in the Image-SIG mailing list archive. Any suggestions would be appreciated.


Thanks,

Mark Shure
<***@ccf.org>
Chris Cogdon
2003-08-26 21:34:07 UTC
Permalink
Post by Mark Shure
Hello,
I'm a relative newcomer to Python and PIL, but I've been using it
successfully for several months. I was stumped by the error I got when I
tried using the ImageDraw.Draw(im) function. Here is what I see when I run
Post by Mark Shure
import Image, ImageDraw
im = Image.open("lena.ppm")
draw = ImageDraw.Draw(im)
File "C:/Python22/imageDraw_test2.py", line 3, in ?
draw = ImageDraw.Draw(im)
File "C:\Python22\lib\site-packages\PIL\ImageDraw.py", line 72, in
__init__ self.draw = Image.core.draw(self.im, blend)
AttributeError: 'module' object has no attribute 'draw'
I'm using Python 2.2.1 under Win2k with PIL 1.1.4 (binaries installed using
"PIL-1.1.4.win32-py2.2.exe").
I haven't been able to find any leads on the web or in the Image-SIG
mailing list archive. Any suggestions would be appreciated.
This isn't complete help, but it might give you some pointers:

- The sequence of instructions above works just fine on my system (linux)

In Image.py, there's a statement that says:

core = _imaging

(There's code in there to put something else in place if _imaging is missing.
However, since the error above refers to 'module', it means that it IS in
fact a module)

So... the 'draw' attribute actually comes from _imaging, which is the
written-in-C module that gets installed along with the rest of the python
modules.

If you're seeing the error you are, it means that the module IS there, but for
some reason is missing the 'draw' method. Looking at the C code there doesn't
seem to be any reason that _imaging would be there, but the draw method would
not. It's totally weird
--
("`-/")_.-'"``-._ Chris Cogdon <***@cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL

_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Chris Cogdon
2003-08-26 21:55:24 UTC
Permalink
Aha... was looking at the wrong version of PIL. From 1.1.4's Image.py version:

try:
# If the _imaging C module is not present, you can still use
# the "open" function to identify files, but you cannot load
# them. Note that other modules should not refer to _imaging
# directly; import Image and use the Image.core variable instead.
import _imaging
core = _imaging
del _imaging
except ImportError, v:
import string
core = _imaging_not_installed()
if str(v)[:20] == "Module use of python":
# The _imaging C module is present, but not compiled for
# the right version (windows only). Print a warning, if
# possible.
try:
import warnings
warnings.warn(
"The _imaging extension was built for another version "
"of Python; most PIL functions will be disabled",
RuntimeWarning
)
except (ImportError, NameError, AttributeError):
pass # sorry


This seems the likely culprit. If true, then it's likely you're using a
version of python different from what the _imaging module was compiled
against.

If it IS true, then I'm surprised you're not seeing the warning. (It's not a
very robust way of handling the warning, though ;)
--
("`-/")_.-'"``-._ Chris Cogdon <***@cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL

_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Fredrik Lundh
2003-08-27 12:29:25 UTC
Permalink
Post by Mark Shure
I'm a relative newcomer to Python and PIL, but I've been using
it successfully for several months. I was stumped by the error I
got when I tried using the ImageDraw.Draw(im) function. Here
is what I see when I run example code straight out of the PIL
AttributeError: 'module' object has no attribute 'draw'
I'm using Python 2.2.1 under Win2k with PIL 1.1.4 (binaries installed
using "PIL-1.1.4.win32-py2.2.exe").
import Image
Image.core
...
Post by Mark Shure
dir(Image.core)
...

and let us know what it prints.

</F>




_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Mark Shure
2003-08-27 15:26:53 UTC
Permalink
Thanks for your suggestions, Chris. I used Steve Miller's Dependency Walker (www.dependencywalker.com) to check the dependencies of "_imaging.pyd". These included PYTHON22.DLL. I'm not sure how much this DLL file changes between 2.2.x sub-releases or whether this is the culprit...

Here is my response to Fredrik's posting:

Fredrik Lundh fredrik at pythonware.com
Post by Fredrik Lundh
import Image
Image.core
...
dir(Image.core)
...
and let us know what it prints.
</F>
Here's what I see on my system:

Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Post by Fredrik Lundh
import Image
Image.core
<module '_imaging' from 'C:\Python22\DLLs\_imaging.pyd'>
Post by Fredrik Lundh
dir(Image.core)
['__doc__', '__file__', '__name__', 'bit_decoder', 'blend', 'convert', 'copy', 'crc32', 'display', 'display_mode', 'effect_mandelbrot', 'effect_noise', 'eps_encoder', 'fill', 'fli_decoder', 'font', 'getcodecstatus', 'gif_decoder', 'gif_encoder', 'hex_decoder', 'hex_encoder', 'jpeg_decoder', 'jpeg_encoder', 'linear_gradient', 'map', 'msp_decoder', 'new', 'open_ppm', 'outline', 'packbits_decoder', 'path', 'pcd_decoder', 'pcx_decoder', 'pcx_encoder', 'radial_gradient', 'raw_decoder', 'raw_encoder', 'sun_rle_decoder', 'tga_rle_decoder', 'tiff_lzw_decoder', 'wedge', 'xbm_decoder', 'xbm_encoder', 'zip_decoder', 'zip_encoder']
Thanks again for all your help, guys!


Regards,

Mark Shure
<***@ccf.org>



_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig

Loading...