簡體   English   中英

exe文件執行失敗

[英]Exe file failed to execute

我正在使用 Python 和 tkinter 構建一個簡單的預測 GUI。 它在 Jupyter 筆記本中運行良好,當我使用nbconvert將文件轉換為 .py 時。 由於我想將該工具傳遞給沒有 python 的人,因此我已使用pyinstaller --onefile Prediction.py將其轉換為 exe。

exe 構建沒有錯誤,但是當我在 cmd 中運行 exe 時,我得到FileNotFoundError: [Errno 2] File b'SRV_Platforms_Yield.csv' does not exist: b'SRV_Platforms_Yield.csv'[5404] Failed to execute script Prediction which意味着它找不到我的訓練文件。 我怎樣才能讓它工作?

這是我的預測工具的代碼:

import pandas as pd
import numpy as np

df = pd.read_csv('SRV_Platforms_Yield.csv')
df.rename(columns={'REPORT FAMILY':'REPORT_FAMILY', 'FPY+':'FPY'},inplace=True)
df['FPY'] = df['FPY'].apply(lambda x: np.nan if x in ['-'] else x[:-1]).astype(float)/100
df = df[['REPORT_FAMILY', 'FPY_TESTED', 'FPY']]
df['REPORT_FAMILY'] = df['REPORT_FAMILY'].astype(str)

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df["REPORT_FAMILY"] = le.fit_transform(df["REPORT_FAMILY"])
print("Class mapping: ")
for i, item in enumerate(le.classes_):
    print(item, "-->", i)

x = df.iloc[:,:-1]
y = df.iloc[:,-1]

from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor(n_estimators= 1000, random_state=42)
rf.fit(x, y)

#tkinter GUI
import tkinter as tk 
#creating the window
window = tk.Tk()
window.title("FPY+ Prediction")

canvas1 = tk.Canvas(window, width = 550, height = 250)
canvas1.pack()

t = tk.Text(window)
canvas1.create_window(270, 250)
for i, item in enumerate(le.classes_):
    t.insert(tk.INSERT, f"{item}-->{i}\n")
t.pack()

# New_Interest_Rate label and input box
label1 = tk.Label(window, text='Type REPORT FAMILY: ')
canvas1.create_window(50, 100, window=label1)

entry1 = tk.Entry (window) # create 1st entry box
canvas1.create_window(270, 100, window=entry1)

# New_Unemployment_Rate label and input box
label2 = tk.Label(window, text='Type FPY_TESTED: ')
canvas1.create_window(60, 130, window=label2)

entry2 = tk.Entry (window) # create 2nd entry box
canvas1.create_window(270, 120, window=entry2)

def values(): 
    global New_REPORT_FAMILY #our 1st input variable
    New_REPORT_FAMILY = entry1.get()
    
    global New_FPY_TESTED #our 2nd input variable
    New_FPY_TESTED = float(entry2.get()) 
    
    Prediction_result  = ('Predicted FPY: ', rf.predict([[New_REPORT_FAMILY ,New_FPY_TESTED]]))
    label_Prediction = tk.Label(window, text= Prediction_result, bg='yellow')
    canvas1.create_window(260, 180, window=label_Prediction)
    
button1 = tk.Button (window, text='Predict FPY',command=values, bg='grey') # button to call the 'values' command above 
canvas1.create_window(270, 150, window=button1)

window.mainloop()

你應該把你的文件'SRV_Platforms_Yield.csv'和.exe文件放在同一個文件夾中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM