import sys, os
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
# "packages": ["os"] is used as example only
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# base="Win32GUI" should be used only for Windows GUI app
base = None
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
include_files = [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')), (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll'))]
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "Snake",
version = "0.1",
description = "A Classic Snake Game with a few Modifications!",
options = {"build_exe": include_files},
executables = [Executable("main.py", base=base)]
That's the setup.py code I'm using cx freeze on. although when I try to run it using python setup.py build the error in the title of this post shows up. tell me if I need to provide more info and thank you in advance!
The build_exe parameter is expected to be a dictionary of parameter/value sets. You need to check the documentation.
https://cx-freeze.readthedocs.io/en/latest/setup_script.html
I suspect you intended:
...
options = {"build_exe": {"include_files": include_files}},
Related
I've spent hours trying to find how to fix this problem but I haven't been able to find anything helpful yet.
So I'm trying to convert a tkinter program to exe using cx_Freeze. Everything works well until I try to open the actual exe file Here's is the error report.
My setup file:
import os
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
os.environ['TCL_LIBRARY'] = r"C:\Users\Osborne-Win10\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll"
os.environ['TK_LIBRARY'] = r"C:\Users\Osborne-Win10\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll"
build_options = dict(
packages=['sys'],
includes=['tkinter'],
include_files=[(r'C:\Users\Osborne-Win10\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll',
os.path.join('lib', 'tcl86t.dll')),
(r'C:\Users\Osborne-Win10\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll',
os.path.join('lib', 'tk86t.dll'))]
)
executables = [
Executable('app.py', base=base)
]
setup(name='simple_Tkinter',
options=dict(build_exe=build_options),
version='0.1',
description='Sample cx_Freeze tkinter script',
executables=executables,
)
and my script:
import tkinter as tk
root = tk.Tk()
tk.Label(root, text='Application', font='Tahoma 15 bold italic').pack()
tk.mainloop()
So if you have any idea what could/is causing the error please let me know!
(Answer edited after the OP has modified the question)
I guess something is wrong with the os.environ definitions. They should point to TCL/TK directories, not to the DLLs. These definitions should read something like:
os.environ['TCL_LIBRARY'] = r"C:\Users\Osborne-Win10\AppData\Local\Programs\Python\Python36\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Users\Osborne-Win10\AppData\Local\Programs\Python\Python36\tcl\tk8.6"
Anyway, it would be much better to let the setup script find dynamically the location of the TCL/TK resources as suggested in this answer:
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
build_options = dict(
packages=['sys'],
includes=['tkinter'],
include_files=[(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.join('lib', 'tcl86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join('lib', 'tk86t.dll'))]
)
I created a small converter and after building it with CX_Freeze it shows this error
Traceback (most recent call last):
File "C:\users\LDC\AppData\Local\Programs\python\python36-32\lib\sitr\e-packages\cx_freeze\initscripts_startup_.py", line14 in run module.run()
File "C:\users\LDC\AppData\Local\Programs\python\python36-32\lib\sitr\e-packages\cx_freeze\initscripts\console.py", line26 in run exec(code,m.dict)
File"GUI1.py",line 1, in
File
"C:\USERS\LDC\APPDATA\LOCAL\PROGRAMS\PYTHON\PYTHON36-32\LIB\TKINTER_INIT_.PY",line36,in
import_tkinter#If this fails your python may not be configured for Tk
ImportError: DLL load failed: the specified module could not be found
This is a screen shot from the error
Now this is my code:
from tkinter import *
window1=Tk()
def convert():
var2=var1.get()
var3=var2*3.785
e2.insert(0,var3)
def clear():
e1.delete(0,END)
e2.delete(0,END)
def quit():
window1.destroy()
var1=IntVar()
label1=Label(window1,text='Gallons',padx=25).grid(row=0,sticky=W)
e1=Entry(window1,width=25,textvariable=var1)
e1.grid(row=0,column=1)
label2=Label(window1,text='Liters',padx=25).grid(row=1,sticky=W)
e2=Entry(window1,width=25)
e2.grid(row=1,column=1)
window1.title("Converter")
window1.geometry("400x200+200+200")
button1= Button(text='convert',command=convert,width=15,).grid(row=4,column=0)
button2= Button(text='clear',command=clear,width=15).grid(row=4,column=1)
button3= Button(text='exit',command=quit,width=15).grid(row=5,column=1)
mymenu=Menu()
mymenu.add_cascade(label='File')
mymenu.add_cascade(label='Edit')
mymenu.add_cascade(label='View')
mymenu.add_cascade(label='Tools')
mymenu.add_cascade(label='Help')
window1.config(menu=mymenu)
window1.mainloop()
and this is the setup code
import cx_Freeze
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("GUI1.py", base=base, icon="clienticon.ico")]
cx_Freeze.setup(
name = "GUI1",
options = {"build_exe": {"packages":["tkinter"], "include_files":["clienticon.ico"]}},
version = "0.01",
description = "Ya Rb",
executables = executables
)
I tried the following with no luck:
1. uninstalled cx freeze and installed it again
2. tried different version of python .. python 2.7
3. tried to use py2exe and pyinstaller got different errors
4. also made sure that the python path in the environment is set correctly
Thanks in advance appreciate your help..
This error is not as bad as it looks. You just need to know the path to your Python installation.
What the error means: you've included the tkinter library but forgotten the tkinter run-times (tk86t.dll and tcl86t.dll). For your script to work you need to include them.
This can be done with the use of include_files statement. A quick search through the installation reveals they are located in a folder called DLLs. We need to give the file path and the file names we want to the setup script. This can be done like this:
"include_files":["<path to python>/Python36-32/DLLs/tcl86t.dll","<path to python>/Python36-32/DLLs/tk86t.dll"]
and it will now work.
Your setup script will look like this:
import cx_Freeze
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("GUI1.py", base=base, icon="clienticon.ico")]
cx_Freeze.setup(
name = "GUI1",
options = {"build_exe": {"packages":["tkinter"], "include_files":["clienticon.ico", "<path to python>/Python36-32/DLLs/tcl86t.dll","<path to python>/Python36-32/DLLs/tk86t.dll"]}},
version = "0.01",
description = "Ya Rb",
executables = executables
)
My program is working in anaconda spyder. however, after freezing it all widgets that use the tkinter module work except for the widget with xgboost and pandas. No error showed, the build worked but the button is not working and not showing the widget.
I've tried importing and including xgboost in my setup.py file but all other widgets with tkinter didn't work altogether. No error still though. have anyone experienced or solved this issue?
Here's the closest thing that worked. This is my setup.py, when the other widgets worked with tkinter but not the one with xgboost and pandas.
from cx_Freeze import setup, Executable
import sys
import os
includes = []
include_files = [r"C:/Users/USER/Anaconda3/DLLs/tcl86t.dll",
r"C:/Users/USER/Anaconda3/DLLs/tk86t.dll",
r"C:/Users/USER/SAMPLE/xgboost_USE.model",
r"C:/Users/USER/SAMPLE/P1.ico"]
os.environ['TCL_LIBRARY'] = "C:/Users/USER/Anaconda3/tcl/tcl8.6"
os.environ['TK_LIBRARY'] = "C:/Users/USER/Anaconda3/tcl/tk8.6"
base = 'Win32GUI' if sys.platform == 'win32' else None
setup(name=application_title, version='1.0', description='SAMPLE',
options={"build_exe": {"includes": includes, "include_files":
include_files}},executables=
[Executable(r'C:/Users/USER/SAMPLE/sample.py', base=base)])
Please help.
I dont have any experience with xgboost but I know when you cx freeze pandas you will need to explicitly include numpy. I'll share a setup file I have that has pandas (and some other things you can delete out like boto I assume)
import sys
import cx_Freeze
import os.path
import scipy
base = None
if sys.platform == 'win32':
base = "Win32GUI"
#This part may depend on where your installation is
#This part is essential to copy the tkinter DLL files over
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
os.environ['REQUESTS_CA_BUNDLE'] = r'C:\ProgramData\Anaconda3\Lib\site-packages\botocore\vendored\requests\cacert.pem'
executables = [cx_Freeze.Executable("test.py", base=base)]
addtional_mods = ['numpy.core._methods', 'numpy.lib.format']
packages = ["idna", "numpy", "boto3", 'boto3.s3.transfer', 'boto3.s3.inject', 'multiprocessing', "xlwt", 'numpy.core._methods', 'pandas']
options = {
'build_exe': {
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.dirname(scipy.__file__),
r'C:\ProgramData\Anaconda3\Lib\site-packages\botocore\vendored\requests\cacert.pem',
r'C:\ProgramData\Anaconda3\Lib\site-packages\botocore',
],
'includes': addtional_mods,
'packages':packages,
},
}
cx_Freeze.setup(
name = "Test",
options = options,
version = "1.0.0.0",
description = 'Test',
executables = executables
)
Im trying to buld my app with selenium, i have this setup.py:
import sys
from cx_Freeze import setup, Executable
path_drivers = ( "C:\Python34\Lib\site-packages\PyQt5\plugins\sqldrivers\qsqlmysql.dll", "sqldrivers\qsqlmysql.dll" )
includes = ["atexit","PyQt5.QtCore","PyQt5.QtGui", "PyQt5.QtWidgets","PyQt5.QtSql", "selenium"]
includefiles = [path_drivers]
excludes = [
'_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter'
]
packages = ["os"]
path = []
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"includes": includes,
"include_files": includefiles,
"excludes": excludes,
"packages": packages,
"path": path
}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
exe = None
if sys.platform == "win32":
exe = Executable(
script="main.py",
initScript = None,
base=None,
targetName="zeus.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "telll",
version = "0.1",
author = 'me',
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [exe]
)
The build finish with no problems, but when i run my application:
ImportError: No module named 'httplib'
My configuration:
Python 3.4.3 32bit.
PyQt5
Selenium 2.46.0
Thaks for the help
httplib either isn't in your directory path or hasn't been imported.
try adding either of these two scripts to your code:
import httplib
httplib = httplib(config_file="your directory path to httplib")
import cx_Freeze
import sys
base = None
if sys.platform == "win32":
base = "Win32GUI"
build_exe_options = {
"include_msvcr": True #skip error msvcr100.dll missing
}
executables = [cx_Freeze.Executable("Clock.pyw",base=base,icon="Icon.ico")]
cx_Freeze.setup(
name= "Clock client",
options = {"build_exe": build_exe_options ,{"packages":["tkinter"],"include_files":["Icon.ico"]}},
version = "0",
description = "Clock program",
executables = executables
)
how is line 13 supposed to be formatted as when I try to compile this code I get the error invalid syntax with the curly bracket highlighted what am I missing?
options = {"build_exe": build_exe_options ,{"packages":["tkinter"],"include_files":["Icon.ico"]}},
This code is wrong, because you shouldn't put the "build_exe_options ," bit.
Corrected:
options = {"build_exe": {"packages":["tkinter"],"include_files":["Icon.ico"]}},