我正在尝试编写一个Python程序,将PDF转换为图像列表,但是出现了错误:TypeError:'NoneType'对象没有len()
Python
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()
File "OCR.py", line 13, in <module> img_page = Image(image=img) TypeError: 'module' object is not callable
。 - Lxs29Image(image=img)
应该是Ima(image=img)
吗? - emcconville