我试图创建一个带有PDF并将其转换为图像列表的python程序,但我遇到了问题:TypeError: object of type 'NoneType' has no len()
from wand.image import Image as Ima
images = []
pdf = Ima(filename="./sample.pdf")
jpeg = pdf.convert('jpeg')
for img in jpeg.sequence:
img_page = Image(image=img)
images.append(img_page.make_blob('jpeg'))
print(images)
File "OCR.py", line 9, in <module>
pdf = Ima(filename="./sample.pdf")
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wand/image.py", line 2744, in __init__
self.read(filename=filename, resolution=resolution)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wand/image.py", line 2822, in read
self.raise_exception()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wand/resource.py", line 222, in raise_exception
raise e
wand.exceptions.DelegateError: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=/var/folders/ll/vhx7d69s27l_766f7fh0w8t80000gn/T/magick-17265E7LIPpQmRZ4H%d' '-f/var/folders/ll/vhx7d69s27l_766f7fh0w8t80000gn/T/magick-17265VZNfoxE7irl0' '-f/var/folders/ll/vhx7d69s27l_766f7fh0w8t80000gn/T/magick-17265OAxHJmx1Guv6'' (1) @ error/pdf.c/InvokePDFDelegate/292
Exception ignored in: <bound method Resource.__del__ of <wand.image.Image: (empty)>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wand/resource.py", line 232, in __del__
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wand/image.py", line 2767, in destroy
TypeError: object of type 'NoneType' has no len()
答案 0 :(得分:0)
我遇到了同样的问题,这里是关于我如何解决它的分步指南,在Mac上安装Wand(0.4)和ImageMagick v6(macOS High Sierra v 10.13.5)
我假设已经安装了ImageMagic,如果没有,请安装它:
brew install imagemagick@6
接下来,使用以下命令创建符号链接(替换为您的特定版本):
ln -s /usr/local/Cellar/imagemagick@6//lib/libMagickWand-6.Q16.dylib /usr/local/lib/libMagickWand.dylib
就我而言,它是:
ln -s /usr/local/Cellar/imagemagick@6/6.9.10-0/lib/libMagickWand-6.Q16.dylib /usr/local/lib/libMagickWand.dylib
安装魔杖
pip3 install Wand
现在,在尝试运行代码时,我收到了类似的错误消息:
wand.exceptions.DelegateError:FailedToExecuteCommand`'gs' -sstdout =%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap = 500000000 -dAlignToPixels = 0 -dGridFitTT = 2'-sDEVICE = pngalpha'-dTextAlphaBits = 4 -dGraphicsAlphaBits = 4'-r72x72' “ -
默认情况下似乎没有安装ghostscript,所以让我们安装它:
brew install ghostscript
现在您需要创建一个指向/ usr / bin的软链接,但OS X 10.11+中的/ usr / bin /受到保护。
请按以下步骤操作: