【问题标题】:py to exe : failed to execute script pyi_rth_win32comgenpypy 到 exe:执行脚本 pyi_rth_win32comgenpy 失败
【发布时间】:2019-12-16 22:05:53
【问题描述】:

我正在使用 tkinter 模块创建一个简单的计算程序,并希望转换为 exe,因为我希望它可以在任何电脑上执行。但不知何故显示错误消息(无法执行脚本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()

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

【问题讨论】:

  • 你可以使用我的py to exe程序:github.com/BlackThunder01001/cx_freeze_GUI
  • @BlackThunder 你是否在脚本中包含了images
  • @ADWAN 你能详细说明你的意思吗?很难说出你在问什么。
  • @BlackThunder 您是否将图像包含为icon 或在labelbutton 上使用图像。
  • @ADWAN 我包含了图标、问号和标题的图片

标签: python tkinter pyinstaller


【解决方案1】:

我卸载了所有与 win32 相关的东西(pypiwin32pywin32pywin32-ctypespywinpty),然后再次安装,神奇地运行了。

herehere 那里汲取灵感。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      您收到此错误 failed to execute script pyi_rth_win32comgenpy 是因为不包括您使用的 images iconslabels

      我包含了图标、问号和标题的图像

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

      【讨论】:

      • 如果您需要任何帮助,可以发表评论。
      • 对不起,我没明白你的意思。我没有包含任何图标(仅首先使用默认图标)。你能详细告诉我吗?对不起,我真的很菜鸟
      猜你喜欢
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 2019-12-21
      • 2021-08-12
      • 2019-03-19
      • 2011-06-28
      相关资源
      最近更新 更多