我想制作一个转换工具,通过pyinstaller,python pdf2image模块将pdf文件更改为jpg文件。
它在 python 脚本(pycharm)上成功执行。但是当我尝试使用这个源制作 exe 文件时,pyinstller 制作的 exe 文件在控制台上显示错误消息,上面写着“无法获取页数。是否安装了 poppler 并在 PATH 中?”
这是我原来的完整脚本
from pdf2image import convert_from_path
pdf_path = "C:/Users/mayun/Documents/Room Service Menu.pdf"
poppler_path = "C:/Users/mayun/Documents/poppler-0.68.0/bin"
try :
images = convert_from_path(pdf_path, poppler_path=poppler_path)
number = 1
for i in images:
file ="C:/Users/mayun/Documents/page_{0}.jpg".format(number)
i.save(file)
print(file)
number = number = number + 1
except BaseException as e:
print (e)
这是 CMD 上用于制作 exe 文件的 pyinstaller 命令
pyinstaller --onefile pdfconvert2.py
我无法理解为什么会发生此错误,仅在 exe 文件中。pycharm中原来的脚本没有问题,同样的源和路径成功了。