简体   繁体   中英

Exe file failed to execute

I'm building a simple Prediction GUI using Python and tkinter. It works fine in the Jupyter notebook and when I converted the file to.py using nbconvert . As I want to pass around the tool to people who don't have python, I have converted it to exe using pyinstaller --onefile Prediction.py .

The exe is build without error, but when I run the exe in the cmd I got FileNotFoundError: [Errno 2] File b'SRV_Platforms_Yield.csv' does not exist: b'SRV_Platforms_Yield.csv'[5404] Failed to execute script Prediction which means that it cannnot find my file for training. How can I make it work?

This is the code for my prediction tool:

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()

you should put your file 'SRV_Platforms_Yield.csv' and.exe file in the same folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM