簡體   English   中英

Python Wand PDF到圖像列表TypeError

[英]Python Wand PDF to List of Images TypeError

我正在嘗試創建一個帶有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()

我有同樣的問題,這里有一個關於我如何解決它的分步指南,在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 /受到保護。

只需按以下步驟操作:

  1. 重新啟動到恢復模式。 啟動聲音后重新啟動並按住“Cmd + R”。
  2. 在恢復模式下,轉到實用程序 - >終端。
  3. 運行:csrutil disable
  4. 在普通模式下重新啟動。
  5. 在終端中執行“sudo ln -s / usr / local / bin / gs / usr / bin / gs”。
  6. 做1和2步驟。 在終端啟用后通過運行返回csrutil:csrutil enable(這些步驟基於

它對我有用,享受!

你可以在這里找到我原來的帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM