[Python] python program malfunction when converted to .exe

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have an issue converting a .py to .exe using pyinstaller .

    The program below works perfectly as a .py, but everything i tried to convert it to .exe with pyinstaller or auto-py-to-exe it gives an .exe file that produces absolutly no result.

    pyinstaller runs an produces an exe file without error, but the exe file gives no result.

    No errors are raised while creating the exe

    The program through an SQL request is supposed to print a list of email comming from a postgresql base.

    I ran the .py in spider and in cmd : everything is ok. i tried runing the exe in cmd, no errors but again : no results

    Here is the .py :

    import psycopg2


    try:

    # connect to PostgreSQL
    conn = psycopg2.connect(

    dbname="xxxx",
    user="xxxx",
    password="xxxx",
    host="postgresql-xxxx-xxxx.xxxx.xxxx",
    port="xxxx" # port par défaut PostgreSQL

    )

    # create cursor for SQL commands
    cursor = conn.cursor()

    # run selection
    cursor.execute("SELECT email FROM membre")

    # get results
    rows = cursor.fetchall()

    # print results

    for row in rows:
    print(row)

    except Exception as e:

    print(f"Une erreur est survenue : {e}")

    finally:
    # close cursor ant conn.
    if cursor:
    cursor.close()

    if conn:
    conn.close()


    here is the code for convertion (i tried with a lot of hide-import, but nothing changes):

    pyinstaller --onefile --hidden-import=psycopg2 --hidden-import=psycopg2._psycopg --hidden-import=psycopg2.extensions --hidden-import=psycopg2.extras --hidden-import=sqlalchemy.dialects.postgresql --hidden-import=sqlalchemy.dialects.postgresql.psycopg2 creation_userform_sans_sql.py


    Thanks a lot for your help !

    i tried to add hidden-imports (a lot !) also tried onefile or not... also tried auto-py-to-exe

    Continue reading...

Compartilhe esta Página