我的问题与如何增加 pandoc 执行中的堆内存有关?,但添加了特定于 Python 的组件。
背景:我正在尝试自动生成科学报告。我已将数据写入 HTML 文件,并且想使用 Pandoc.exe(文件转换程序)将其转换为 .docx Word 文档。我已经掌握了处理带有图像、表格等的较小 HTML 文件的流程。该文件为 307KB。
当我尝试转换嵌入多个图形的较大文件(~4.5MB)时,问题就开始了。我一直在使用pypandoc转换,如下所示:
import pypandoc
PANDOC_PATH = r"C:\Program Files\RStudio\bin\pandoc"
infile = savepath + os.sep + 'Results ' + name + '.html'
outfile = savepath + os.sep + 'Results ' + name + '.docx'
output = pypandoc.convert(source=infile, format='html', to='docx', \
outputfile=outfile, extra_args=["+RTS", "-K64m", "-RTS"])
Run Code Online (Sandbox Code Playgroud)
但我遇到了各种各样的错误。通常:
RuntimeError: Pandoc died with exitcode "2" during conversion:
b"Stack space overflow: current size 33692 bytes.\nUse `+RTS -Ksize -RTS' to increase …Run Code Online (Sandbox Code Playgroud)