Как удалить всплывающее окно терминала из исполняемого файла PyInstaller, созданного в macOS High Sierra? - PullRequest
0 голосов
/ 31 октября 2018

Я создал исполняемый файл Python (версия 2.7.15) с помощью PyInstaller на MacOS High Sierra.

Но каждый раз, когда я запускаю исполняемый файл, он также открывает окно терминала, которое я не хочу открывать. Я прочитал много вопросов по этому поводу. Как предлагается во многих ответах, я пытался "--noconsole", "--windowed" при сборке приложения. Я попытался изменить "filename.py" на "filename.pyw". Я также попытался настроить файл .spec, созданный после сборки. Но никакое решение не работает для меня.

Может кто-нибудь предложить что-нибудь о том, как это исправить, если у них была такая же проблема?

#Importing required packages
import os
import codecs
import pandas as pd
from datetime import datetime
import Tkinter, tkFileDialog

#Defining global variables
account=[]
date_obj=[]
amt=[]
txn_amt=[]
Total_amt=[]
final_amt=[]
atm=[]
atm_fees=[]
cd=os.getcwd()

#Asking the user to give path to the Kasasa txt file and creating a new text file(newfile.txt)
root = Tkinter.Tk()
root.withdraw()
open_path = tkFileDialog.askopenfilename()
file = open(open_path, 'r')
NewFile = codecs.open(cd+"/newfile.txt", 'w')
wanted_txns=['D068','D076'] #Specifying the required tranasction types in string varaible

#Using only transactions of type "D068" and "D076" to append to a new txt file
for line in file:
    if any(ttype in line for ttype in wanted_txns):
        NewFile.write(line)

#opening newly created txt file having only transactions of kind "D068" and "D076"
contents = codecs.open(cd+"/newfile.txt","r").readlines()        # store the entire file into a string variable
os.remove(cd+"/newfile.txt")

for each in contents:
    account.append(each.split("D", 1))
    txn_amt.append(each.split("+",1))

for each in txn_amt:
    amt.append(each[0].split("D",1))

Total_amt=[item[1][9:] for item in amt]

#Function for getting Account_Number
def get_cif_num():
    cif_num = [item[0] for item in account]
    cif_num=[s.replace('"', '') for s in cif_num]
    return cif_num

#Function for getting TXN_Types
def get_txn_type():
    txn_type = [item[1][0:3] for item in account]
    return txn_type

#Function for getting TXN_Dates
def get_prcs_date():
    txn_date = [item[1][3:9] for item in account]
    for i in xrange(0,len(txn_date)):
        date_obj.append((datetime.strptime(txn_date[i], '%m%d%y').date().strftime('%m-%d-%Y')))
    return date_obj

#Function for getting Total TXN_Amounts
def get_txn_amt():
    for i in xrange(0,len(Total_amt)):
        final_amt.append(round(float(Total_amt[i])/100,2))
    return final_amt

#Function for getting ATM charges
def get_atm_fees():
    for i in xrange(0,len(Total_amt)):
        atm.append(round(float(Total_amt[i])%1000,2)) #taking remainder of division by 1000
    for i in xrange(0,len(atm)):
        atm_fees.append(round(float(atm[i])/100,2))
    return atm_fees

#storing returned list output of each function in separate variables
a=get_cif_num()
b=get_txn_type()
c=get_prcs_date()
d=get_txn_amt()
e=get_atm_fees()

#Storing the variables in pandas dataframe "df" with the column names
cols=['CIF_NUMBER','TRANSACTION_TYPE','PROCESSNG_DATE','TOTAL_AMOUNT','ATM_FEES']
df = pd.DataFrame(
    {'CIF_NUMBER': a,
    'TRANSACTION_TYPE': b,
    'PROCESSNG_DATE' :c,
    'TOTAL_AMOUNT':d,
    'ATM_FEES':e})

#Putting null in the "ATM_FEES" column if the "TXN_TYPE" is 068
df.loc[df['TRANSACTION_TYPE'] == '068', 'ATM_FEES'] = ''
# move the column "CIF_NUM" to the first position using index, pop and insert
cols.insert(0, cols.pop(cols.index('CIF_NUMBER')))
# use ix to reorder the columns
df = df.ix[:, cols]  
print(df)

#Asking the user to specify the path to the output CSV file
root = Tkinter.Tk()
root.withdraw()
saving_path = tkFileDialog.asksaveasfile(mode='w', defaultextension=".csv")
df.to_csv(saving_path)
...