簡體   English   中英

創建的 Python 腳本合並 PDF 文件在 Pycharm 中工作正常,但不是作為我通過 pyinstaller 制作的單獨 EXE

[英]Created Python Script to merge PDF files works fine in Pycharm but not as a solo EXE I made via pyinstaller

所以這是我下面的代碼。如標題中所述,它在 PyCharm 中按預期工作,但不在其之外。 會不會是因為我使用了 PyPDF2 庫? 謝謝您的任何幫助將不勝感激。

import os

from PyPDF2 import PdfFileMerger

def main():

    print("PDF Merger Initialized")

    pdfs = [pdf_file for pdf_file in os.listdir() if pdf_file.endswith(".pdf")] #sets pdfs as a list containing all files with the .pdf extenstion

    merger = PdfFileMerger()

    for pdf in pdfs:
        merger.append(pdf)

    merger.write("merged_bills.pdf")
    merger.close()


    print("PDF Merger Completed")


main()

試試吧

import glob

pdfs = [pdf_file for pdf_file in glob.glob(os.path.join(os.getcwd(),"*.pdf")]

glob 將以這種方式返回文件的完整路徑

或者嘗試

pdfs = [os.path.join(os.getcwd(),pdf_file) for pdf_file in os.listdir(os.getcwd()) if pdf_file.endswith(".pdf")]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM