我正在尝试在我已安装的Ubuntu服务器中将pdf文件转换为图像文件:
我的代码:
from pdf2image import convert_from_path, convert_from_bytes
images = convert_from_path("/home/user/pdf_file.pdf")
# OR
with open("/home/user/pdf_file.pdf") as pdf:
images = convert_from_bytes(pdf.read())
输出值
当我使用功能“ convert_from_path”时
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pdf2image/pdf2image.py", line 143, in convert_from_path
thread_output_file = next(output_file)
TypeError: ThreadSafeGenerator object is not an iterator
当我使用功能“ convert_from_bytes”时
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/local/lib/python2.7/dist-packages/pdf2image/pdf2image.py", line 268, in convert_from_bytes
paths_only=paths_only,
File "/usr/local/lib/python2.7/dist-packages/pdf2image/pdf2image.py", line 143, in convert_from_path
thread_output_file = next(output_file)
TypeError: ThreadSafeGenerator object is not an iterator
我已经重新安装了所有实用程序,然后遇到了这些问题。
我也在python2中失败了,但是在python3中成功了。
在另一个库上发生了相同的问题:TypeError:'threadsafe_iter'对象不是迭代器
正如他们所说,这是python 2 vs 3问题,由next()函数引起。
如果在文件中修改__next__()
-> ,它将在py2中成功运行。next()
/home/***/.local/lib/python2.7/site-packages/pdf2image/generators.py
顺便说一句,我已经为pdf2image团队创建了新期刊。
TypeError:ThreadSafeGenerator对象不是迭代器#133
额外的
pdf2image自述文件表示这是python(3.5+)模块。
pdf2image v1.7.1适用于py27。尝试一下pip install pdf2image==1.7.1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句