将.py脚本转换为.exe时出错[Gooey GUI]

时间:2019-07-29 14:46:48

标签: python user-interface exe pyinstaller cx-freeze

我有一个Python脚本,可创建一个Gooey GUI窗口并执行一些操作。下面是摘要版本。

我正在寻找一种简单的解决方案,以将GUI分发给不知道cmd中任何编码和/或基本命令的用户。我的Gooey无法与Anaconda一起使用,因此我一直试图将脚本转换为.exe文件,但是无论是pyinstaller还是cx_Freeze(执行脚本失败),我都会遇到相同的错误。我不确定如何继续...

可能的解决方案,但我不确定在哪里实现: https://github.com/chriskiehl/Gooey/issues/58

我尝试过的一些事情: https://chriskiehl.com/article/packaging-gooey-with-pyinstaller

import pandas as pd
from gooey import Gooey, GooeyParser
import numpy as np
import xlsxwriter
import xlrd

nonbuffered_stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
sys.stdout = nonbuffered_stdoutb

@Gooey(program_name="FEC-app")
def parse_args():
    parser = GooeyParser()

    parser.add_argument('data_file',
                        action='store',
                        widget='FileChooser',
                        help="Excel file from SAP G/L View")

    parser.add_argument('parked_and_noted',
                        action='store',
                        widget='FileChooser',
                        help="Only Parked and Noted Items")

    parser.add_argument('deleted_items',
                        action='store',
                        widget='FileChooser',
                        help="Only Deleted Items")

    args = parser.parse_args()
    return args

def combine(file, file2, file3):
    gl_df = pd.read_excel(file)
    parked_df = pd.read_excel(file2)
    delete_df = pd.read_excel(file3)

    numbers = gl_df['Document Number'].tolist()

    gl = gl_df.append(parked_df[~parked_df['Document Number'].isin(numbers)])
    gl = gl.append(delete_df[~delete_df['Document Number'].isin(numbers)])

    gl = gl.reset_index()

    return gl

def transform(gl):

    gl['JournalCode'] = gl['Document Type']
    gl['JournalLib'] = gl['Document Header Text']
    gl['EcritureNum'] = gl['Document Number']
    gl['EcritureDate'] = gl['Posting Date']
    gl['CompteNum'] = gl['G/L Account']
    gl['CompteLib'] = gl['G/L Account']
    gl['CompAuxLib'] = gl['Offsetting acct no.']
    gl['PieceRef'] = gl['Reference']
    gl['EcritureLib'] = gl['Text']
    gl['Amount'] = gl['Amount in local currency']
    gl['MontantDevise'] = gl['Amount in loc.curr.2']
    gl['Idevise'] = 'USD'
    gl['PieceDate'] = gl['Document Date']
    gl['ValidDate'] = gl['Entry Date']
    gl['EcritureLet'] = gl['Assignment']
    gl['DateLet'] = gl['Entry Date']

    gl.loc[gl["Amount"] < 0 ,'Credit'] = gl['Amount']
    gl.loc[gl["Amount"] > 0 ,'Debit'] = gl['Amount']

    gl.loc[gl["Debit"].isnull() ,'Debit'] = 0
    gl.loc[gl["Credit"].isnull() ,'Credit'] = 0

    gl.loc[gl["EcritureLet"].isnull(),'DateLet'] = ''
    gl.loc[gl["EcritureLet"].isnull(),'DateLet'] = ''

    gl.loc[(gl.Debit == 0) & (gl.Credit == 0),'MontantDevise'] = gl['MontantDevise']
    gl.loc[(gl.Debit != 0) | (gl.Credit != 0),'MontantDevise'] = ''
    gl.loc[gl["MontantDevise"] == '','Idevise'] = ''

## some more code here

gl['DocDate'] = gl['Document Date']

    gl.loc[gl["PieceRef"].isnull(),'PieceRef'] = gl["JournalLib"].map(str) + " " + gl.DocDate.dt.strftime('%Y%m%d').astype(str)

    gl['Document Date'] = gl['DocDate']
    del gl['DocDate']
    gl['EcritureLib'] = gl['EcritureLib'].apply(lambda x: x.upper())

    return gl
def save_results(df):
    writer = pd.ExcelWriter("sample.xlsx",
                        engine='xlsxwriter',
                        datetime_format='yyyymmdd',
                        date_format='yyyymmdd')

    df.to_excel(writer, sheet_name = ('Sheet 1'))


    workbook  = writer.book
    worksheet = writer.sheets['Sheet 1']
    worksheet.set_column('B:C', 20)
    writer.save()

if __name__ == '__main__':
    args = parse_args()

    gl_items = args.data_file
    parked = args.parked_and_noted
    delete = args.deleted_items

    output_df = combine(gl_items,parked,delete)
    print("Reading data and combining with parked and deleted items")
    print("Separating Debits and Credits")
    print("Mapping Vendors")
    output_df_translated = transform(output_df)
    print("Translating to French")
    print("Mapping French Accounts")
    print("Filling in blanks")
    save_results(output_df_translated)
    print("Done")
    print("Your file is called: sample and is located in the Downloads folder")



0 个答案:

没有答案