[Python] .app made using PyInstaller closes straight away?

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    I have attempted to convert my python program into a .app using PyInstaller. The actual code runs fine through IDLE, but everytime I try and run the newly converted .app, it closes straight away. Below is my .spec file and my .py file. I have edited the .spec file, adding in the text file I import in my .py file.

    PYTHON FILE:


    #CENTRALCOAST: 2250-2420
    #CENTRALCOAST2: 2250-2267
    #NORTHERNBEACHES: 2084-2108
    CentralCoast = []
    NorthernBeaches = []
    OOR = []
    Invalid = []
    import math
    def numLen(num):
    return len(str(abs(num)))

    with open('postcodes.txt') as input_file:
    long_list = [line.strip() for line in input_file]
    for i in range(len(long_list)):
    long_list = int(long_list)
    for each in long_list:
    if 2084 <= each <= 2108: #NorthernBeaches
    NorthernBeaches.extend([each])
    for each in long_list:
    if 2250 <= each <= 2267: #CentralCoast
    CentralCoast.extend([each])
    for each in long_list:
    if not 2250 <= each <= 2267:
    OOR.extend([each])
    #for each in long_list:
    # if numLen(each) != 4:
    # Invalid.extend([each])

    Total = len(CentralCoast) + len(OOR) + len(NorthernBeaches) + len(Invalid)

    print("Central Coast:", len(CentralCoast), "------", round(len(CentralCoast)/Total,2), "%")
    print("")
    print("Northern Beaches:", len(NorthernBeaches), "------", round(len(NorthernBeaches)/Total,4), "%")
    print("")
    print("Out of Range:", len(OOR), "------", round(len(OOR)/Total,2), "%")
    print("")
    #i = 0
    #for i in OOR:
    # print(i)
    # i = i + 1
    print("Invalid Entry:", len(Invalid), "------", round(len(Invalid)/Total,4), "%")
    print("")
    print("")
    print("Total:", Total)
    exit = input("")

    SPEC FILE:


    # -*- mode: python -*-

    block_cipher = None


    a = Analysis(['algorithmPOSTCODE.py'],
    pathex=['/Users/CooperTimewell'],
    binaries=[],
    datas=[('postcodes.txt', '.')],
    hiddenimports=[],
    hookspath=[],
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher)
    pyz = PYZ(a.pure, a.zipped_data,
    cipher=block_cipher)
    exe = EXE(pyz,
    a.scripts,
    exclude_binaries=True,
    name='algorithmPOSTCODE',
    debug=False,
    strip=False,
    upx=True,
    console=False )
    coll = COLLECT(exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    name='algorithmPOSTCODE')
    app = BUNDLE(coll,
    name='algorithmPOSTCODE.app',
    icon=None,
    bundle_identifier=None)

    How do I stop it from closing straight away? Thankyou.

    Continue reading...

Compartilhe esta Página