我一起使用这三个时遇到问题。我相信魔杖无法识别ImageMagick库,但我不确定。
环境:Python 3.5.1 :: Anaconda 4.0.0 (64位)视窗 7
我采用的设置说明:
- 安装了带有"C/C++开发"的 ImageMagick-6.9.4-Q8 (x64)已选中标头选项。(安装到 C:\程序文件\图像魔术-6.9.4-Q8)
- Set MAGICK_HOME envar C:\Program Files\ImageMagick-6.9.4-Q8
- 从皮普安装的魔杖
我的代码:
import wand
...
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
...
追踪:
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'
从我所看到的一切来看,我都遵循了正确的设置说明。我正在使用 64 位版本的 ImageMagick 和 64 位版本的 Anaconda。这在我开始使用Anaconda之前一直和我一起工作(在我使用常规的32位Python和32位ImageMagick之前)。
我错过了什么吗?为什么魔杖不能正常工作?
试试这个
from wand.image import Image
with Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
pass
我错过了什么吗?为什么魔杖不能正常工作?
我相信它正在按预期工作,并且原始架构师不打算允许顶级包级快捷方式(即 import wand
)。这有点有意义,因为魔杖与 ctypes 集成到 IM 中,并且在setup.py
期间不会尝试解析库。
您可以通过添加以下内容来修改包以包含您期望的模块快捷方式。
# 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
但我不推荐这个。from package.module import Class
干净得多。
如果您使用的是 PIL。图像,然后使用:
from wand.image import Image as wand_image_Image
import PIL