繁体   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