简体   繁体   中英

Wand + ImageMagick + Anaconda: “'wand' has no attribute 'image'”

I'm having issues using these three together. I believe wand is not recognizing the ImageMagick libraries but I'm not sure.

Environment: Python 3.5.1 :: Anaconda 4.0.0 (64-bit) Windows 7

Set up instructions I took:

  1. Installed ImageMagick-6.9.4-Q8 (x64) with the "C/C++ development headers options checked. (Installed to C:\\Program Files\\ImageMagick-6.9.4-Q8)
  2. Set MAGICK_HOME envar C:\\Program Files\\ImageMagick-6.9.4-Q8
  3. Installed wand from pip

My code:

import wand
...
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
...

Traceback:

    Traceback (most recent call last):
  File ".\pdf_convert.py", line 31, in <module>
    ret = pdf2jpg(f, target_file, 2480)
  File ".\pdf_convert.py", line 10, in pdf2jpg
    with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
AttributeError: module 'wand' has no attribute 'image'

From everything I've seen I've followed the right setup instructions. I am using the 64 bit version of ImageMagick with the 64 bit version of Anaconda. This was working with me before until I started using Anaconda (before I was using regular 32 bit Python and 32 bit ImageMagick.)

Is there something I'm missing? Why is wand not working correctly?

Try this

from wand.image import Image

with Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
    pass

Is there something I'm missing? Why is wand not working correctly?

I believe it is working as expected, and the original architect did not intend to allow top-package-level shortcuts (ie import wand ). This kinda makes sense as integrates to IM with , and does not attempt to resolve libraries during setup.py .

You can modify the package to include the module shortcuts your expecting by adding the following.

# wand/__init__.py
import api
import color
import compat
import display
import drawing
import exceptions
import font
import image
import resource
import sequence
import version

But I wouldn't recommend this. The from package.module import Class is a lot more cleaner.

如果您也使用 PIL.Image,请使用:

from wand.image import Image as wand_image_Image
import PIL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM