简体   繁体   中英

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

So this is my code below.AS stated in the title it works as intended in PyCharm but not outside of it. Would it be because I used PyPDF2 library? Thank you any help would be much appreciated.

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()

try instead

import glob

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

glob will return the full path to the file in this way

alternatively try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM