使用 pyinstaller 在 exe 文件中包含 poppler

问题描述

我尝试编写一个简单的程序来将 PDF 文件转换为 JPG。主要思想是一个简单的 .exe 文件,它将在同一目录中找到所有 PDF 文件,并将它们转换为 JPG 后将它们放在新文件夹中。 我做到了!使用 pdf2image,我的程序完全按照我的意愿和 .py 和 .exe 执行。但是,在另一台 PC 上运行此程序后,popper >following Cmd 屏幕截图出现错误

image of cmd prompt showing error: "Unable to get page count. Is Poppler installed and in PATH?"

所以,我明白,该程序试图找到一个 popper。并且肯定在另一台 PC 上找不到它。

我试过--hidden-import、--onedir、--onefile 等。 也在这里看到了一些类似的问题,如:

PyInstaller and Poppler

Include poppler while generating an application using pyinstaller

但是,或者我做错了什么,或者在这道题中无法清楚地理解如何做解决方案。

我该怎么办?

#P.S.也许,有更好的库或模块来创建这种程序?

完整代码

import os
import pdf2image
from pdf2image import convert_from_path
from inspect import getsourcefile
from pdf2image.exceptions import (
                                    PDFInfonotinstalledError,pdfpageCountError,PDFSyntaxError
)

#  Create output direction
#  Direction of executable file
script_dir = os.path.abspath(getsourcefile(lambda:0))
#  print(script_dir)
output_dir = 'JPG'

#  List for files which wasn't converted
error_list = []

#  If path don't exist - create
if not os.path.exists(output_dir):
    os.makedirs(output_dir)
    #print('Path has been created',"\n")
else:
    pass
    #print('Directory exist',"\n")

#  Show all files in directory
file_list = os.listdir()
print(file_list,"List of files")

for file in file_list:
    
    try:
        # print(file)
        pages = convert_from_path(file,dpi=300,fmt='jpg',output_folder=output_dir,output_file=file)
    
    except Exception as e: print(e)


print("File wasn't converted:","\n")
if len(error_list) == 0:
    print(0,"\n")
else:
    for f in error_list:
        print(f)

input("Done! Press Enter")

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...