web-dev-qa-db-fra.com

cx_freeze donne typeError: astucieux STR, octets ou objet OS.Path, pas non neuf

J'essaie de préparer un exécutable à l'aide de CX_FREEE, mais obtenez l'erreur suivante:

Traceback (most recent call last):
  File "setup.py", line 19, in <module>
    executables = executables
  File "C:\Users\q499593\AppData\Roaming\Python\Python37\site-packages\cx_Freeze\dist.py", line 342, in setup
    distutils.core.setup(**attrs)
  File "C:\Program Files\Python37\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Program Files\Python37\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Program Files\Python37\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Program Files\Python37\lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "C:\Program Files\Python37\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Program Files\Python37\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\q499593\AppData\Roaming\Python\Python37\site-packages\cx_Freeze\dist.py", line 217, in run
    freezer.Freeze()
  File "C:\Users\q499593\AppData\Roaming\Python\Python37\site-packages\cx_Freeze\freezer.py", line 645, in Freeze
    self._WriteModules(fileName, self.Finder)
  File "C:\Users\q499593\AppData\Roaming\Python\Python37\site-packages\cx_Freeze\freezer.py", line 536, in _WriteModules
    sourcePackageDir = os.path.dirname(module.file)
  File "C:\Program Files\Python37\lib\ntpath.py", line 221, in dirname
    return split(p)[0]
  File "C:\Program Files\Python37\lib\ntpath.py", line 183, in split
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Je suis nouveau à Python et je ne suis pas sûr de savoir pourquoi je reçois cette erreur, voici mon code:

import pandas as pd
import numpy as np
from sklearn import linear_model
from sklearn.model_selection import train_test_split
from scipy.sparse.csgraph import _validation
from tkinter import *
from scipy.spatial import ckdtree

print(ckdtree.cKDTree)

filepath = r'O:\TI-6\TI-67\09_Intern\09-06_Temporaere_MA\Mustafa\02_xxx-arbeit\GUI\LIST_50er_Refined.xlsx'
X = pd.read_Excel(filepath, usecols="A:F", header=0) #import Excel data
Y = pd.read_Excel(filepath, usecols="G", header=0)
df_x=pd.DataFrame(data=X) #Excel to dataframe to use in ML
df_y=pd.DataFrame(data=Y)
#np_array = df.values #dataframe
#print(X) #printing dataframe
#print(Y)

reg=linear_model.LinearRegression()
x_train,x_test,y_train, y_test = train_test_split(df_x,df_y,test_size=0.2,random_state=4)
reg.fit(x_train,y_train)
a=reg.predict(x_test)
mse = np.mean((a-y_test)**2)


def prediction(test_values):
    predict=reg.predict(test_values)
    return predict


root = Tk()
root.title("Prediction Tool")

width = 1024  # screen dimensions
height = 520  # screen dimensions
screen_width = root.winfo_screenwidth()  # screen dimensions
screen_height = root.winfo_screenheight()  # screen dimensions
x = (screen_width / 2) - (width / 2)  # screen dimensions
y = (screen_height / 2) - (height / 2)  # screen dimensions
root.geometry("%dx%d+%d+%d" % (width, height, x, y))  # screen dimensions
root.resizable(True, True)  # screen Resizable set to true
#root.state('zoomed')
root.config(bg="#000000")  # home screen background color - black
button1 = Button(root, text='Press to enter values to predict the Cooling Time', fg='white', bg='red',
                     command=lambda: ShowAddNew(), height=1, width=100)
button1.grid(row=10, column=2, padx=160, pady=250)
# ========================================VARIABLES========================================
JOB_HEIGHT = IntVar()
LAYERS = IntVar()
PARTS = IntVar()
DENSITY = DoubleVar()
LOCATION_NUMBER = IntVar()
ROOM_TEMPERATURE = DoubleVar()
RESULT = DoubleVar()
TEMPERATURE = DoubleVar()

# ========================================METHODS==========================================
def Home(): # Home screen/main menu dimensions and features
    global Home
    Home = Toplevel()
    Home.title("Cooling Prediction Tool")
    width = 1024
    height = 520
    screen_width = Home.winfo_screenwidth()
    screen_height = Home.winfo_screenheight()
    x = (screen_width / 2) - (width / 2)
    y = (screen_height / 2) - (height / 2)
    Home.geometry("%dx%d+%d+%d" % (width, height, x, y))
    Home.resizable(True, True)
    Home.state('zoomed')
    Title = Frame(Home, bd=1, relief=SOLID)
    Title.pack(pady=10)
    lbl_display = Label(Title, text="Prediction System", font=('arial', 45))
    lbl_display.pack()
    ShowAddNew()


def ShowAddNew(): # - screen dimensions
    global addnewform
    addnewform = Toplevel()
    addnewform.title("Prediction System/Predict")
    width = 800
    height = 750
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    x = (screen_width / 2) - (width / 2)
    y = (screen_height / 2) - (height / 2)
    addnewform.geometry("%dx%d+%d+%d" % (width, height, x, y))
    addnewform.resizable(True, True)
    #addnewform.state('zoomed')
    addnewform.protocol("WM_DELETE_WINDOW", lambda: on_closing(addnewform))
    AddNewForm()


def AddNewForm(): # Add new item entries and details
    TopAddNew = Frame(addnewform, width=600, height=100, bd=1, relief=SOLID)
    TopAddNew.pack(side=TOP, pady=20)
    lbl_text = Label(TopAddNew, text="Predict Cooling Time", font=('arial', 18), width=600)
    lbl_text.pack(side=TOP)
    MidAddNew = Frame(addnewform, width=600)
    MidAddNew.pack(side=TOP, pady=50)
    lbl_Temp = Label(MidAddNew, text="Temperatur[°C]:", font=('arial', 15), bd=10)
    lbl_Temp.grid(row=0, sticky=W)
    lbl_infoo = Label(MidAddNew, text="Hinweis: immer 50", font=('arial', 9), bd=10)
    lbl_infoo.grid(row=0, column=2)
    lbl_JobHeight = Label(MidAddNew, text="Job Höhe [mm]:", font=('arial', 15), bd=10)
    lbl_JobHeight.grid(row=1, sticky=W)
    lbl_layersqty = Label(MidAddNew, text="Anzahl Schichten:", font=('arial', 15), bd=10)
    lbl_layersqty.grid(row=2, sticky=W)
    lbl_parts = Label(MidAddNew, text="Anzahl Teile:", font=('arial', 15), bd=10)
    lbl_parts.grid(row=3, sticky=W)
    lbl_density = Label(MidAddNew, text="Packungsdichte[%]:", font=('arial', 15), bd=10)
    lbl_density.grid(row=4, sticky=W)
    lbl_infoo2 = Label(MidAddNew, text="Hinweis: immer im Dezimal eingeben", font=('arial', 9), bd=10)
    lbl_infoo2.grid(row=4, column=2)
    lbl_RoomTemp = Label(MidAddNew, text="Raum Temperatur[°C]:", font=('arial', 15), bd=10)
    lbl_RoomTemp.grid(row=5, sticky=W)
    temperature = Entry(MidAddNew, textvariable=TEMPERATURE, font=('arial', 15), width=15)
    temperature.grid(row=0, column=1)
    jobheight = Entry(MidAddNew, textvariable=JOB_HEIGHT, font=('arial', 15), width=15)
    jobheight.grid(row=1, column=1)
    layers = Entry(MidAddNew, textvariable=LAYERS, font=('arial', 15), width=15)
    layers.grid(row=2, column=1)
    parts = Entry(MidAddNew,textvariable= PARTS, font=('arial', 15), width=15)
    parts.grid(row=3, column=1)
    density = Entry(MidAddNew, textvariable=DENSITY, font=('arial', 15), width=15)
    density.grid(row=4, column=1)
    RoomTemperature = Entry(MidAddNew, textvariable=ROOM_TEMPERATURE, font=('arial', 15), width=15)
    RoomTemperature.grid(row=5, column=1)
    btn_add = Button(MidAddNew, text="Calculate", font=('arial', 15), width=10, bg="#009ACD")
    btn_add.grid(row=6, columnspan=6, pady=20)
    btn_add.configure(command=lambda: AddNew(lbl_text, MidAddNew))

def AddNew(lbl_heading, frame_window):
    if TEMPERATURE.get == "" or JOB_HEIGHT.get() == "" or JOB_HEIGHT.get() <= 0 or LAYERS.get() <= 0 or LAYERS.get() == "" or PARTS.get() <= 0 or PARTS.get() == "" or DENSITY.get() == "" or DENSITY.get() <= 0 or ROOM_TEMPERATURE.get() == "" or ROOM_TEMPERATURE.get() <= 0:
        lbl_heading.config(text="Bitte füllen Sie die erforderlichen Felder aus!", fg="red")
    else:
       print([TEMPERATURE.get(), JOB_HEIGHT.get(), LAYERS.get(), PARTS.get(), DENSITY.get(), ROOM_TEMPERATURE.get()])
       test_data=[TEMPERATURE.get(), JOB_HEIGHT.get(), LAYERS.get(), PARTS.get(), DENSITY.get(), ROOM_TEMPERATURE.get()]
       test_array=np.asarray(test_data)
       test_array=test_array.reshape(1,-1)
       RESULT.set(float(prediction(test_array)))
       print(str(RESULT.get()))
       TEMPERATURE.set(0)
       PARTS.set(0)
       LAYERS.set(0)
       DENSITY.set(0)
       ROOM_TEMPERATURE.set(0)
       JOB_HEIGHT.set(0)
       lbl_heading.config(text="Abkühlzeit ist : " + str(RESULT.get()) + " mins!")
       frame_window.destroy()

def on_closing(win): # close (x) button if clicked, resets all values
    TEMPERATURE.set(0)
    PARTS.set(0)
    LAYERS.set(0)
    DENSITY.set(0)
    ROOM_TEMPERATURE.set(0)
    JOB_HEIGHT.set(0)
    win.destroy()
# ========================================FRAME============================================
Title = Frame(root, bd=1, relief=SOLID)

# ========================================INITIALIZATION===================================
if __name__ == '__main__':
    root.mainloop()

et voici mon fichier setup.py:

from cx_Freeze import setup, Executable

base = None

executables = [Executable("Abkuehlzeit_HP_GUI.py", base=base)]

packages = ["idna","pandas","numpy","sklearn","tkinter","sklearn.model_selection"]
options = {
    'build_exe': {
        'packages':packages,
    },
}

setup(
    name = "Prediction_Tool",
    options = options,
    version = "1.0",
    description = '',
    executables = executables
)

Remarque: j'ai essayé de faire un exécutable à l'aide de Pyinstaller et il a fonctionné, mais la structure des sous-dossiers et des fichiers dans le dossier de destination est vraiment non organisée, la structure de CX_FREEEE est beaucoup plus organisée. Toute aide serait appréciée :)

5
Saad Mustafa

Je viens d'avoir le même problème. Vous êtes correct que la réduction de la vitesse CX_FREEEE à 6.1 la corrige. J'ai également trouvé une autre solution de contournement: supprimer (ou déplacer quelque part d'autre) le répertoire lib\site-packages\numpy\random\_examples.

Il semble être réparé par ceci: https://github.com/marcelotduart/cx_freeze/pull/695 afin que nous puissions nous attendre à ce que la version 6.3 puisse résoudre ce problème lorsqu'il est publié éventuellement.

Le problème (ou un très similaire) est mentionné dans https://github.com/marcelotduart/cx_freeze/issues/692 et https://github.com/marcelotduart/cx_freeze/Problèmes/705 . Un commentaire dans # 705 suggère également d'éliminer l'utilisation de replace_paths comme une solution de contournement (qui ne s'applique pas à votre cas particulier mais pourrait à d'autres).

Jusqu'à 6.3 est publié, si la réduction de la rétrogradation de 6,1 n'est pas une option, vous pouvez essayer de mettre à jour la version de développement en cours à l'aide de pip install -U git+https://github.com/marcelotduarte/cx_Freeze.git@master (à vos risques et périls).

4
user1224797

Vous avez assigné base = aucun. Ajouter les lignes suivantes après cela -

if sys.platform == 'win32':
    base = 'Win32GUI'
0
tan_an