KeyError: 'TCL_Library' when I use cx_Freeze
You can work around this error by setting the environment variables manually:
set TCL_LIBRARY=C:\Program Files\Python35-32\tcl\tcl8.6
set TK_LIBRARY=C:\Program Files\Python35-32\tcl\tk8.6
You can also do that in the setup.py
script:
os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tk8.6'
setup([..])
But I found that actually running the program doesn't work. On the cx_freeze mailinglist it was mentioned:
I have looked into it already and no, it is not just a simple recompile --
or it would have been done already! :-)It is in progress and it looks like it will take a bit of effort. Some of
the code in place to handle things like extension modules inside packages
is falling over -- and that may be better solved by dropping that code and
forcing the package outside the zip file (another pull request that needs
to be absorbed). I should have some time next week and the week following
to look into this further. So all things working out well I should put out
a new version of cx_Freeze before the end of the year.
But perhaps you have more luck ... Here's the bug report.
KeyError: 'TCL_LIBRARY' when building using cx_freeze
cx_freeze does not work with python 3.7 so switching to 3.6 allowed it to work, then adding
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')
sets the directory in order to use ctypes
Error after converting tkinter program to exe using cx_Freeze and running the exe file
(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'))]
)
Related Topics
How to Account for Period (Am/Pm) Using Strftime
Prime Number Check Acts Strange
Sorting Text File by Using Python
How to Create a View Onto a Numpy Array
Python Script to Copy Text to Clipboard
Counting Repeated Characters in a String in Python
How to Make a Multidimension Numpy Array with a Varying Row Size
Append to a List Defined in a Tuple - Is It a Bug
_Csv.Error: Field Larger Than Field Limit (131072)
Absolute VS. Explicit Relative Import of Python Module
Pandas "Can Only Compare Identically-Labeled Dataframe Objects" Error
How to Handle Elements Inside Shadow Dom from Selenium
How to Login to a Website with Python