简体   繁体   English

Wand + ImageMagick + Anaconda:“'wand' 没有属性 'image'”

[英]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.我相信魔杖无法识别 ImageMagick 库,但我不确定。

Environment: Python 3.5.1 :: Anaconda 4.0.0 (64-bit) Windows 7环境:Python 3.5.1 :: Anaconda 4.0.0(64 位)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)安装 ImageMagick-6.9.4-Q8 (x64) 并选中“C/C++ 开发头文件选项。(安装到 C:\\Program Files\\ImageMagick-6.9.4-Q8)
  2. Set MAGICK_HOME envar C:\\Program Files\\ImageMagick-6.9.4-Q8设置 MAGICK_HOME 环境 C:\\Program Files\\ImageMagick-6.9.4-Q8
  3. Installed wand from pip从 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.我将 64 位版本的 ImageMagick 与 64 位版本的 Anaconda 一起使用。 This was working with me before until I started using Anaconda (before I was using regular 32 bit Python and 32 bit ImageMagick.)在我开始使用 Anaconda(在我使用常规 32 位 Python 和 32 位 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 ).我相信它按预期工作,原始架构师不打算允许顶级包级快捷方式(即import wand )。 This kinda makes sense as integrates to IM with , and does not attempt to resolve libraries during setup.py .这有点有意义,因为使用集成到 IM,并且不会在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. from package.module import Class更加简洁。

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

from wand.image import Image as wand_image_Image
import PIL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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