Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 286
DataDude Avatar asked Sep 02 '25 03:09

DataDude


2 Answers

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 (i.e. import wand). This kinda makes sense as wand integrates to IM with ctypes, 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.

like image 182
emcconville Avatar answered Sep 05 '25 00:09

emcconville


If you are using PIL.Image as well then use:

from wand.image import Image as wand_image_Image
import PIL

like image 30
Aaj Kaal Avatar answered Sep 04 '25 23:09

Aaj Kaal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!