使用 pyinstaller 转换 python 脚本后,Exe 文件无法按预期工作

发布于 2025-01-17 18:56:40 字数 1011 浏览 4 评论 0原文

我正在尝试使用Python自动将PDF-Docs转换为PNG-DOC(PDF2Image)。到目前为止,Python-Script的工作原理,但是当我尝试将我的小程序员分发给其他人(使用Pyinstaller将脚本转换为Exe-File)时,会出现问题。但是,当我运行python script时,任务是正确执行的,但是启动EXE后,任务几乎没有发生。

不幸的是,我在编码方面几乎没有经验,而且我的代码可能很费力,但是如果有人可以帮助我,我会非常感谢。

from pdf2image import convert_from_path
import os
from pathlib import Path


absolutePath = os.path.dirname(os.path.abspath(__file__)) 
newlist = [] 
counter = 1


def collectPDF(): 
    items = os.listdir(absolutePath)
    for names in items:
        if names.endswith('.pdf'):
            newlist.append(names) 
        number = list(range(100))
        for numb in number:
            if names.endswith(str(numb) + '.png'):
                exit()


def convert(filename):
    pages = convert_from_path(absolutePath + '/' + filename, 300)
    for page in pages:
        global counter
        page.save(absolutePath + '/' + str(counter) + '.png', 'PNG')
        counter += 1

collectPDF()
for name in newlist:
    convert(name)
del newlist[:] 

I am trying to use python to automate the conversion of pdf-docs into png-docs (pdf2image). So far the python-script works as hoped, but when I try to distribute my little programm to other people (using pyinstaller to convert the script into a exe-file) something goes wrong. However, when I run my python-script the task is executed properly, but after starting the exe literally nothing happens.

Unfortunalety I have few experience in coding and my code might be laborious but I will be very thankful, if someone can help me.

from pdf2image import convert_from_path
import os
from pathlib import Path


absolutePath = os.path.dirname(os.path.abspath(__file__)) 
newlist = [] 
counter = 1


def collectPDF(): 
    items = os.listdir(absolutePath)
    for names in items:
        if names.endswith('.pdf'):
            newlist.append(names) 
        number = list(range(100))
        for numb in number:
            if names.endswith(str(numb) + '.png'):
                exit()


def convert(filename):
    pages = convert_from_path(absolutePath + '/' + filename, 300)
    for page in pages:
        global counter
        page.save(absolutePath + '/' + str(counter) + '.png', 'PNG')
        counter += 1

collectPDF()
for name in newlist:
    convert(name)
del newlist[:] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文