使用 pyinstaller 转换 python 脚本后,Exe 文件无法按预期工作
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论