Reputation: 661
I'm trying to create an executable for my application using cx_Freeze and I keep getting the same error when I try and add additional libraries. The following code works fine without trying to 'import numpy'. I originally thought the error was from having multiple files and incorrectly scripting my setup file so that is why I have the code split up.
ToDotExe.py
from mathLibrary import *
from tkinter import *
from tkinter import simpledialog
window=Tk()
btn = Button(window, text = "This prompts a dialog box for 5x",command = lambda: timesByFive(window))
btn.grid()
btn2 = Button(window, text = "This prompts a dialog box for cosx",command = lambda: operatebycos(window))
btn2.grid()
window.title("Basic Calculator")
window.geometry("300x200+10+20")
window.mainloop()
MathLibrary.py
from tkinter import simpledialog
from numpy import cos
def timesByFive(master):
answer = 1
while not answer is None:
answer = simpledialog.askinteger("Input", "What would you like to times by 5?",
parent=master)
print(answer)
try:
print (answer*5)
except TypeError:
if answer is None:
break
pass
def operatebycos(master):
answer = 1
while not answer is None:
answer = simpledialog.askinteger("Input", "What would you like to operate on by cos?",
parent=master)
print(answer)
try:
print (cos(answer))
except TypeError:
if answer is None:
break
pass
Setup.py
from cx_Freeze import setup,Executable
includes = []
excludes = []
packages = ["tkinter","numpy"]
includefiles = []
setup(
name = 'toDotExe',
version = '0.1',
description = 'A general enhancement utility',
author = 'YosTruly',
author_email = '[email protected]',
options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable('toDotExe.py')]
)
Error:
Traceback (most recent call last):
File "setup.py", line 15, in <module>
executables = [Executable('toDotExe.py')]
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\dist.py", line 342, in setup
distutils.core.setup(**attrs)
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\dist.py", line 217, in run
freezer.Freeze()
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\freezer.py", line 645, in Freeze
self._WriteModules(fileName, self.finder)
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\freezer.py", line 536, in _WriteModules
sourcePackageDir = os.path.dirname(module.file)
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 221, in dirname
return split(p)[0]
File "C:\Users\Jerwin\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 183, in split
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
C:\Users\Jerwin\Desktop\Trying to create .Exe>
Upvotes: 0
Views: 144
Reputation: 579
I had a similar issue that cxfreeze somehow got wrong set of libraries. I had to remove those erratic libs after building, then copy & paste those from site-packages folder of my anaconda environment.
Upvotes: 0
Reputation: 5065
I would suggest you use pyinstaller
.
pip install pyinstaller
pyintaller --onefile -w ToDotExe.py
The flag --onefile
will give you a single exe file instead of a bunch of other files. Whereas -w
this will stop python from bringing up the console/terminal during execution.
Note: Only use -w
only when your console doesn't require the console to remain open. (Don't use it if you are taking input from the user, for example).
You can watch this video for more information.
You can also refer to the official documentation
Upvotes: 1