Python: CX_Freeze issue after build - python

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
)

Related

cx freeze : AttributeError: 'list' object has no attribute 'items'

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}},

Error after converting tkinter program to exe using cx_Freeze and running the exe file

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'))]
)

cxfreeze widget with tkinter xgboost not showing but no error

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
)

cx_Freeze with Tkinter

I'm a french so sorry for my english.
I actually create a Python 3.6.1 program that use tkinter, paramiko, telnetlib and many other, and I want to create an exe with cx_Freeze. With a "Hello World" program it success, but when I try with just Tkinter, it doesn't work. I have a screen of the error because I can't see it more than 0.5 seconds the terminal when I run the exe. So I join that screen with my setup.py.
setup.py:
import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = r'C:\LOCAL_TO_PYTHON\Python35-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\LOCAL_TO_PYTHON\Python35-32\tcl\tk8.6'
executables= [cx_Freeze.Executable('exeTest.py',)]
cx_Freeze.setup(
name = "leTest",
options = {'built.exe':{'includes': ['tkinter','paramiko','telnetlib']}},
version = "1.0",
description = "Bonjour !",
executables = executables,
)
error:
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\__startup.py", in line 12, in <module>
__import__(name+"__init__")
File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", in line 24, in <module>
exec(code, m.__dict__)
File "exeTest.py", line 9, in <module>
File "C:\Python36\lib\tkinter\__init.py", in line 36, in <module>
import _tkinter # If this fails your Python may not be configured fot Tk
ImportError: DLL load failed: The specified module can not be found.
Thanks for reading and maybe for the help
Give this a try. Pretty sure this will assume your Python install is part of your PATH.
import sys
import os
from cx_Freeze import setup, Executable
import cx_Freeze
import tkinter
import os.path
import scipy
base = None
if sys.platform == 'win32':
base = "Win32GUI"
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['TCL_LIBRARY'] = r'C:\Users\matthew\Downloads\WinPython-64bit-3.5.3.0Qt5\python-3.5.3.amd64\tcl\tcl8.6'
#os.environ['TK_LIBRARY'] = r'C:\Users\matthew\Downloads\WinPython-64bit-3.5.3.0Qt5\python-3.5.3.amd64\tcl\tk8.6'
executables = [cx_Freeze.Executable("exeTest.py", base=base)]
addtional_mods = ['numpy.core._methods', 'numpy.lib.format']
packages = ["idna", "numpy",]
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__),
],
'includes': addtional_mods,
'packages':packages,
},
}
cx_Freeze.setup(
name = "letest",
options = options,
version = "0.01",
description = 'Bonjour',
executables = executables
)

exe error with cx_freeze

Hey am relatively new to compiling python scripts to exe. Im using cx_freeze to compile my scripts and once its built i run the exe and it gives me this error. Have google around alot but not too sure. Error is:
Cannot import traceback module.
Exception: No module named re
Original Exception: No module named re
Not too sure how to go about fixing this. I read that possibly there is a clash between a module named re? in python? and a module named re in cx_freeze module?
My setup file looks like:
from cx_Freeze import setup, Executable
includes = []
includefiles = ['remindersText.pkl']
eggsacutibull = Executable(
script = "podlancer.py",
initScript = None,
base = 'Win32GUI',
targetName = "podlancer.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "Podlancer",
version = "0.1",
author = 'jono',
description = "Podlancer UI script",
options = {"build_exe": {"includes":includes, "include_files": includefiles}},
executables = [eggsacutibull]
)
Try to change
includes = []
to
includes = ["re"]
That worked for me
cx_freeze will barf if the runtime working directory is not the directory that the executable is in.
Is re the first import you do? What happens when you do them in a different order?
Meeting this same problem putting re in includes didn't work for me. It produced a cx_Freeze.freezer.ConfigError when rebuilding the .py file.
import sys
from cx_Freeze import setup, Executable
build_exe_options = {'include_files': ['re']}
setup( name = "Foreground Window Montior",
version = "0.1",
description = "Query the foreground window.",
options = {'build_exe': build_exe_options},
executables = [Executable("actWin_Query.py")])
If I put re in packages rather than in include_files it did not produce this compile error.
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["re"]}
setup( name = "Foreground Window Montior",
version = "0.1",
description = "Query the foreground window.",
options = {'build_exe': build_exe_options},
executables = [Executable("actWin_Query.py")])

Categories