如何停止 python 中的内存错误以进行 pdf 转换?

How to stop Memory Error in python for pdf conversion?

我目前正在使用 pdf2image - 一个 poppler 包装器 - 将 pdf 转换为枕头图像,以便我可以查看 pdf。但是,无论我使用什么 pdf,我总是会收到以下错误:

Traceback (most recent call last):
File "C:\Users\karee\AppData\Local\Programs\Python\Python39-32\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:\Users\karee\AppData\Local\Programs\Python\Python39-32\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\karee\AppData\Local\Programs\Python\Python39-32\lib\subprocess.py", line 1479, in _readerthread
    buffer.append(fh.read())
MemoryError

有什么方法可以解决这个问题,除非更改我计算机上的规格或换一台新的? 这是我的代码:

root = Tk()
pdf_frame = Frame(root).pack(fill=BOTH, expand=1)
scrol_y = Scrollbar(pdf_frame, orient=VERTICAL)
pdf = Text(pdf_frame, yscrollcommand=scrol_y.set, bg="grey")
scrol_y.pack(side=RIGHT, fill=Y)
scrol_y.config(command=pdf.yview)
pdf.pack(fill=BOTH, expand=1)
pages = convert_from_path('Books/Keeper Of The Lost Cities/Everblaze ( PDFDrive ).pdf', size=(800, 900),
                          poppler_path=r"poppler-21.03.0\Library\bin")
photos = []
for i in range(len(pages)):
    photos.append(ImageTk.PhotoImage(pages[i]))
for photo in photos:
    pdf.image_create(END, image=photo)

    pdf.insert(END, '\n\n')
mainloop()

如有任何帮助,我们将不胜感激。

每次批量转换 PDF,例如 5 个。即,

from pdf2image import pdfinfo_from_path,convert_from_path
info = pdfinfo_from_path(pdf_file, userpw=None, poppler_path=None)

maxPages = info["Pages"]
for page in range(1, maxPages+1, 10) : 
   convert_from_path(pdf_file, dpi=200, first_page=page,