[Python] Subprocess fails in PyInstaller package

Discussão em 'Python' iniciado por Stack, Junho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on PyInstaller Packaging. But subprocess isn't seem to be working. Subrocess part it getting stuck and not getting further. But i'm getting return code 0 error.

    Test.py

    import pandas
    import os
    import sys
    import subprocess

    if getattr(sys, 'frozen', False):
    base_path = os.path.dirname(sys.executable)
    else:
    base_path = os.path.dirname(os.path.abspath(__file__))
    t_path = os.path.join(base_path, "_internal", "T.py")
    command = [sys.executable, f"{t_path}/Data/T.py"]
    result = subprocess.run(command, capture_output=True, text=True)


    T.py

    import os
    import sys
    import pandas as pd

    if getattr(sys, 'frozen', False):
    base_path = os.path.dirname(sys.executable)
    else:
    base_path = os.path.dirname(os.path.abspath(__file__))

    excel_path = os.path.join(base_path, 'Data', 'Data.xlsx')
    df = pd.read_excel(excel_path)
    print(df)


    Test.spec

    from PyInstaller.utils.hooks import collect_submodules

    a = Analysis(
    ['Test.py'],
    pathex=[],
    binaries=[],
    datas=[
    ('T.py', 'T.py'),
    ('Data/Data.xlsx', 'Data'),
    ],
    hiddenimports=collect_submodules('pandas') + collect_submodules('openpyxl'),
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
    )

    Continue reading...

Compartilhe esta Página