Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cx_Freeze gives TypeError: expected str, bytes or os.PathLike object, not NoneType

I am trying to prepare an executable using cx_Freeze but get the following error :

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

I am new to Python and I am not sure why I am getting this error, here is my 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()

and here is my setup.py file :

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
)

Note : I tried making an executable using Pyinstaller and it worked, however the structure of the sub-folders and files in the destination folder is really unorganized, the structure of cx_Freeze is much more organized. Any help would be appreciated :)

like image 942
Sam Avatar asked Jul 17 '20 09:07

Sam


1 Answers

I just had the same issue. You're correct that downgrading cx_Freeze to 6.1 fixes it. I also found another workaround: delete (or move someplace else) the directory lib\site-packages\numpy\random\_examples.

It seems to be fixed by this: https://github.com/marcelotduarte/cx_Freeze/pull/695 so we can expect version 6.3 to fix this when it's released eventually.

The problem (or a very similar one) is mentioned in https://github.com/marcelotduarte/cx_Freeze/issues/692 and https://github.com/marcelotduarte/cx_Freeze/issues/705. A comment in #705 also suggests eliminating the use of replace_paths as a workaround (which doesn't apply to your particular case but might to others).

Until 6.3 is released, if downgrading to 6.1 is not an option, you may want to try updating to the current development version using pip install -U git+https://github.com/marcelotduarte/cx_Freeze.git@master (at your own risk).

like image 185
user1224797 Avatar answered Oct 23 '22 23:10

user1224797