Python 无法执行Exe文件

Python 无法执行Exe文件,python,python-3.x,pandas,tkinter,pyinstaller,Python,Python 3.x,Pandas,Tkinter,Pyinstaller,我正在使用Python和tkinter构建一个简单的预测GUI。它在Jupyter笔记本中运行良好,当我使用nbconvert将文件转换为.py时。当我想把这个工具传递给没有python的人时,我使用pyinstaller--onefile Prediction.py将它转换为exe exe是无错误生成的,但是当我在cmd中运行exe时,我得到了FileNotFoundError:[Errno 2]文件b'SRV_Platforms_Yield.csv'不存在:b'SRV_Platforms_Y

我正在使用Python和tkinter构建一个简单的预测GUI。它在Jupyter笔记本中运行良好,当我使用
nbconvert
将文件转换为.py时。当我想把这个工具传递给没有python的人时,我使用
pyinstaller--onefile Prediction.py
将它转换为exe

exe是无错误生成的,但是当我在cmd中运行exe时,我得到了
FileNotFoundError:[Errno 2]文件b'SRV_Platforms_Yield.csv'不存在:b'SRV_Platforms_Yield.csv'[5404]无法执行脚本预测
,这意味着它找不到我的培训文件。我怎样才能让它工作

这是我的预测工具的代码:

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文件放在同一个文件夹中

我想你应该把exe frm build文件夹复制到你的主目录中,文件
SRV_Platforms_Yield.csv
exists@CoolCloud你是对的,但我的回答是这样的,因为他只使用了一个文件“SRV\u Platforms\u Yield.csv”。但总的来说,他需要调动所有人files@CoolCloud谢谢你…它现在工作了…所以…如果我给人们exe文件。我应该给他们一个像zip文件一样的文件,对吗?所有的库,文件和csv。我读到他们用NSIS来that@NurAtiqah是的,你可以使用NSIS,你不必在你的zip中包含.spec、build或dist文件夹