如何从macOS High Sierra上创建的PyInstaller可执行文件中删除终端弹出窗口?

时间:2018-10-30 21:22:44

标签: python-2.7 pyinstaller macos-sierra

我已经在macOS High Sierra上使用PyInstaller创建了Python(2.7.15版)可执行文件。

但是,每次我运行可执行文件时,它也会打开一个终端窗口,而我不想将其打开。我在这方面读了很多问题。正如许多答案所建议的那样,在构建应用程序时,我尝试了“ --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)

0 个答案:

没有答案