py到exe:无法执行脚本pyi_rth_win32comgenpy

时间:2019-08-09 07:32:56

标签: python tkinter pyinstaller

我正在使用tkinter模块创建一个简单的计算程序,并希望转换为exe,因为我希望它可以在任何pc上执行。但是以某种方式显示了错误消息(无法执行脚本pyi_rth_win32comgenpy)。

我尝试使用pyinstaller(cmd和GitHub上的一个:https://github.com/brentvollebregt/auto-py-to-exe),但无济于事。我也尝试使用两种类型的python文件(.py和.pyw)

from tkinter import *
from tkinter.filedialog import askopenfilename
import pandas as pd
from tkinter import messagebox
from pandastable import Table, TableModel

class Window(Frame):

    def __init__(self, master =None):
        Frame.__init__(self, master)

        self.master = master
        self.init_window()

    def init_window(self):

        self.master.title('GUI')
        self.pack(fill=BOTH, expand=1)

        quitButton = Button(self, text='quit', command=self.client_exit)
        quitButton.place(x=0, y=230)

        # fileButton = Button(self, text='Browse Data Set', command=self.import_data)
        # fileButton.place(x=150, y=0)

        fileButton = Button(self, text='SBO', command=self.sbo)
        fileButton.place(x=200, y=50)

        fileButton = Button(self, text='CBO', command=self.cbo)
        fileButton.place(x=150, y=50)


        # menu = Menu(self.master)
        # self.master.config(menu=menu)
        # 
        # file = Menu(menu)
        # file.add_command(label='Save',command=self.client_exit)
        # file.add_command(label='Exit', command= self.client_exit)
        # menu.add_cascade(label='File', menu=file)
        # 
        # edit = Menu(menu)
        # edit.add_command(label='Undo')
        # menu.add_cascade(label='Edit', menu=edit)

    def client_exit(self):
        exit()

    # def import_data(self):
    #
    #     csv_file_path = askopenfilename()
    #     # print(csv_file_path)
    #     df = pd.read_excel(csv_file_path)
    #     return df

    def sbo(self):

        csv_file_path = askopenfilename()
        df = pd.read_excel(csv_file_path)

        data = df.drop(df.index[0])  # remove first row



        data['BOVal%'] = data['BOVal%'].astype(str)  # convert to string
        data['BOQty%'] = data['BOQty%'].astype(str)
        data['CustomerPONo'] = data['CustomerPONo'].astype(str)
        data['OrdNo'] = data['OrdNo'].astype(str)
        data['VendorNo'] = data['VendorNo'].astype(str)

        pivot = data.pivot_table(index='Style', aggfunc='sum')  # first pivot
        pivoted = pd.DataFrame(pivot.to_records())  # flattened
        pivoted = pivoted.sort_values(by=['BOVal'], ascending=False)  # sort largest to smallest

        pivoted['Ranking'] = range(1, len(pivoted) + 1)  # Ranking

        cols = pivoted.columns.tolist()
        cols = cols[-1:] + cols[:-1]
        pivoted = pivoted[cols]
        pivoted = pivoted.set_index('Ranking')

        col = df.columns.tolist()
        col = (col[22:23] + col[15:17] + col[:14] + col[17:22] + col[23:37])  # rearrange column
        data = df[col]

        data = data.sort_values(by=['BOVal'], ascending=False)  # sort value

        data['Ranking'] = range(1, len(data) + 1)  # Set rank
        colm = data.columns.tolist()
        colm = colm[-1:] + colm[:-1]  # rearrange rank column
        data = data[colm]

        data = data.set_index('Ranking')

        # sumboval = data['BOVal'].sum()
        # sumboqty = data['BOQty'].sum()

        # rounded = sumboval.round()

        dates = data['SnapShotDate']
        # print(dates)
        dates = dates.iloc[1].strftime('%d%m%Y')

        sos = data['SOS']
        sos = sos[2]



        result = pivoted.iloc[:10, :3]

        # Create a Pandas Excel writer using XlsxWriter as the engine.
        writer = pd.ExcelWriter('%s SBO %s .xlsx' % (sos, dates), engine='xlsxwriter')

        # Write each dataframe to a different worksheet.
        result.to_excel(writer, sheet_name='pivot')
        df.to_excel(writer, sheet_name=dates)
        data.to_excel(writer, sheet_name='SBO')

        # Close the Pandas Excel writer and output the Excel file.
        writer.save()

        messagebox.showinfo("Note", "Calculation Completed")

    def cbo(self):

        csv_file_path = askopenfilename()
        Stylemat = askopenfilename()
        df = pd.read_excel(csv_file_path)
        sm = pd.read_excel(Stylemat)

        df = df.drop(df.index[0])
        df.insert(loc=8, column='PH', value=['' for i in range(df.shape[0])])
        df.insert(loc=9, column='Site', value=['' for i in range(df.shape[0])])

        df['Region'] = df['Region'].fillna('"NA"')

        df['S&OP Style Aggrt'] = df['S&OP Style Aggrt'].astype(str)
        sm['Style'] = sm['Style'].astype(str)


        dates = df['Date_Rp']
        # print(dates)
        dates = dates.iloc[1]
        w = list(dates)
        w[1] = '-'
        w[3] = '-'
        temp = w[0]
        w[0] = w[2]
        w[2] = temp
        dates = "".join(w)


        rowcount = len(df)
        rowstyle = len(sm)

        i = 0
        j = 0
        Style = []

        for i in range(rowcount):

            for j in range(rowstyle):

                if df.iloc[i, 7] == sm.iloc[j, 0]:
                    df.iloc[i, 8] = 'Horizon'
                    df.iloc[i, 9] = sm.iloc[j, 2]



        table = pd.pivot_table(df[df.PH == 'Horizon'], index='S&OP Style Aggrt', columns='Region',
                               values='Net CBO Value', aggfunc='sum')

        table['Grand Total'] = table.sum(axis=1)

        table = table.sort_values(by=['Grand Total'], ascending=False)

        table['Ranking'] = range(1, len(table) + 1)

        # Create a Pandas Excel writer using XlsxWriter as the engine.
        writer = pd.ExcelWriter('CBO %s .xlsx' % dates, engine='xlsxwriter')

        # Write each dataframe to a different worksheet.
        table.to_excel(writer, sheet_name='pivot')
        df.to_excel(writer, sheet_name=dates)
        sm.to_excel(writer, sheet_name='StyleMat')

        # Close the Pandas Excel writer and output the Excel file.
        writer.save()

        messagebox.showinfo("Note", "Calculation Completed")


root = Tk()
root.geometry('400x300')

app = Window(root)

root.mainloop()

我想知道如何找到此错误的主要原因以及在哪里寻找它,是我的脚本编制方法不正确还是我需要任何其他文件或模块。提前感谢您的帮助。谢谢

3 个答案:

答案 0 :(得分:0)

由于没有包含您曾经使用过的failed to execute script pyi_rth_win32comgenpyimages导致的错误icons

  

我包括了图标,问号和标题的图像

复制此图像,并将其包含在您具有labels可执行文件的目录中。

答案 1 :(得分:0)

我卸载了与win32相关的所有内容(class User { private KeycloakUser keycloakUser; private OtherUser otherUser; } User user = new User(); userService.saveUser(user); // UserService void saveUser(User user) { UserEntity userEntity = userMapper.toUserEntity(user.getOtherUser()); userRespository.save(userEntity); CreateUserRequest request = userMapper.toCreateUserRequest(user.getKeycloakUser()); keyCloakClient.createUser(request); } // UserMapper UserEntity toUserEntity(OtherUser user) { UserEntity result = new UserEntity(); result.setName(user.getName()); return resut; } pypiwin32pywin32pywin32-ctypes),然后再次安装并神奇地工作了。

herehere中吸取灵感。

答案 2 :(得分:-1)

这已经很晚了,但该问题的答案只是exe的py无法在numpy 1.17上执行。降级为numpy 1.16后,程序可以正常运行。