Wand 无法打开现有文件
Wand can't open existing file
我想打开一个 pdf
文件并只获取第一页并将其另存为图像。
我用过 this solution 并且效果很好。它在我的本地环境中仍然有效,但最近在 Travis 中无法正常工作。
所以是的,这段代码来自我的 unittest
,我正在尝试 运行 在 Travis 中使用它。
我有一个测试 pdf
文件,我想打开它:
import os
from wand.image import Image
root_path = 'some/correct/path'
filename = 'two_page_pdf.pdf'
full_path = os.path.join(root_parg, filename)
Image(file=open(full_path, mode='rb'), resolution=300) # Error!!!
-----------------------------------------------
DelegateError
Traceback (most recent call last)
<ipython-input-2-1b1fd9537a14> in <module>()
----> 1 Image(file=open(full_path, mode='rb'), resolution=300)
~/virtualenv/python3.5.3/lib/python3.5/site-packages/wand/image.py in __init__(self, image, blob, file, filename, format, width, height, depth, background, resolution)
2738 b'buffer.' + format)
2739 if file is not None:
-> 2740 self.read(file=file, resolution=resolution)
2741 elif blob is not None:
2742 self.read(blob=blob, resolution=resolution)
~/virtualenv/python3.5.3/lib/python3.5/site-packages/wand/image.py in read(self, file, filename, blob, resolution)
2820 r = library.MagickReadImage(self.wand, filename)
2821 if not r:
-> 2822 self.raise_exception()
2823
2824 def close(self):
~/virtualenv/python3.5.3/lib/python3.5/site-packages/wand/resource.py in raise_exception(self, stacklevel)
220 warnings.warn(e, stacklevel=stacklevel + 1)
221 elif isinstance(e, Exception):
--> 222 raise e
223
224 def __enter__(self):
DelegateError: Postscript delegate failed `/tmp/magick-5ypXvY6l': No such file or directory @ error/pdf.c/ReadPDFImage/677
检查文件:
os.path.isfile(full_path) == True
len(open(full_path, mode='rb').read()) == 18386
环境:
- python 3.5.3
- 魔杖 0.4.4
怎么了?我卡住了。请帮忙
UPD 1:
Imagemagick pack好像跟这个有关!上次测试在版本 8:6.6.9.7-5ubuntu3.9
时通过,更新到 8:6.7.7.10-6ubuntu3.9
后停止工作
更新 2:
.travis.yml
文件。
language: python
sudo: false
cache: pip
python: "3.5"
services:
- rabbitmq
addons:
apt:
packages:
- imagemagick
- python-enchant
此错误的原因是缺少 PDF 委托 (ghostscript
)。我刚刚将此应用程序添加到 addons > apt > packages
travis.yml 部分
我想打开一个 pdf
文件并只获取第一页并将其另存为图像。
我用过 this solution 并且效果很好。它在我的本地环境中仍然有效,但最近在 Travis 中无法正常工作。
所以是的,这段代码来自我的 unittest
,我正在尝试 运行 在 Travis 中使用它。
我有一个测试 pdf
文件,我想打开它:
import os
from wand.image import Image
root_path = 'some/correct/path'
filename = 'two_page_pdf.pdf'
full_path = os.path.join(root_parg, filename)
Image(file=open(full_path, mode='rb'), resolution=300) # Error!!!
-----------------------------------------------
DelegateError
Traceback (most recent call last)
<ipython-input-2-1b1fd9537a14> in <module>()
----> 1 Image(file=open(full_path, mode='rb'), resolution=300)
~/virtualenv/python3.5.3/lib/python3.5/site-packages/wand/image.py in __init__(self, image, blob, file, filename, format, width, height, depth, background, resolution)
2738 b'buffer.' + format)
2739 if file is not None:
-> 2740 self.read(file=file, resolution=resolution)
2741 elif blob is not None:
2742 self.read(blob=blob, resolution=resolution)
~/virtualenv/python3.5.3/lib/python3.5/site-packages/wand/image.py in read(self, file, filename, blob, resolution)
2820 r = library.MagickReadImage(self.wand, filename)
2821 if not r:
-> 2822 self.raise_exception()
2823
2824 def close(self):
~/virtualenv/python3.5.3/lib/python3.5/site-packages/wand/resource.py in raise_exception(self, stacklevel)
220 warnings.warn(e, stacklevel=stacklevel + 1)
221 elif isinstance(e, Exception):
--> 222 raise e
223
224 def __enter__(self):
DelegateError: Postscript delegate failed `/tmp/magick-5ypXvY6l': No such file or directory @ error/pdf.c/ReadPDFImage/677
检查文件:
os.path.isfile(full_path) == True
len(open(full_path, mode='rb').read()) == 18386
环境:
- python 3.5.3
- 魔杖 0.4.4
怎么了?我卡住了。请帮忙
UPD 1:
Imagemagick pack好像跟这个有关!上次测试在版本 8:6.6.9.7-5ubuntu3.9
时通过,更新到 8:6.7.7.10-6ubuntu3.9
更新 2:
.travis.yml
文件。
language: python
sudo: false
cache: pip
python: "3.5"
services:
- rabbitmq
addons:
apt:
packages:
- imagemagick
- python-enchant
此错误的原因是缺少 PDF 委托 (ghostscript
)。我刚刚将此应用程序添加到 addons > apt > packages
travis.yml 部分